from flask import request from bson import ObjectId from models import Account from utils import get_current_time from config import account_collection, users_collection from flask_restful import Resource from simplejwt import jwt class CreateAccount(Resource): def post(self): token = request.headers.get("Authorization") if token == None: return { "message": "token required" }, 401 payload = jwt.decode("DBA", token, "HS256")[1] username = payload['username'] user = users_collection.find_one({ "username": username }) if user == None: return {"message": "user not found"}, 404 body = request.json acc_num = body["acc_num"] acc_type = body["acc_type"] newAccount = Account() newAccount.acc_num = acc_num newAccount.acc_type = acc_type newAccount.username = username account_collection.insert_one(newAccount.__dict__) return({"message":"created successfully", "data":{ "acc_num": acc_num, "acc_type": acc_type, "balance": 0, }})