Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update email to username in account/create #470

Merged
merged 1 commit into from
Jan 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions src/controllers/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,11 @@ import { check, validationResult } from 'express-validator';

export class AccountController {
public static createValidator = [
check('user')
check('username')
.exists()
.withMessage('user is required')
.isObject()
.withMessage('user property should be valid object')
.bail(),
check('user.primaryEmail')
.exists()
.withMessage('user.primaryEmail is required')
.trim()
.isEmail()
.withMessage('primaryEmail is not a valid email id')
.bail(),
.withMessage('username is required')
.isString()
.withMessage('username should be a unique valid string'),
];
/**
* @openapi
Expand Down Expand Up @@ -338,7 +330,7 @@ export class AccountController {
public async create(request: Request, response: Response) {
// For now we keep temporary 1-1 relation between user and customer
// So the flow is:
// 1. Get LogToPrimaryEmail from request body
// 1. Get username from request body
// 2. Check if the customer exists
// 2.1. if no - Create customer
// 3. Check is paymentAccount exists for the customer
Expand All @@ -355,15 +347,15 @@ export class AccountController {
return response.status(StatusCodes.BAD_REQUEST).json({ error: result.array().pop()?.msg });
}

const logToUserEmail = request.body.user.primaryEmail;
const username = request.body.username;

try {
// 2. Check if the customer exists
if (response.locals.customer) {
customer = response.locals.customer as CustomerEntity;
} else {
// 2.1 Create customer
customer = (await CustomerService.instance.create(logToUserEmail)) as CustomerEntity;
customer = (await CustomerService.instance.create(username)) as CustomerEntity;
if (!customer) {
return response.status(StatusCodes.BAD_REQUEST).json({
error: 'Customer creation failed',
Expand Down
Loading