Skip to content

Commit

Permalink
Fix linter issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nickviola committed Dec 1, 2023
1 parent bc9359a commit 1a5911f
Showing 1 changed file with 40 additions and 116 deletions.
156 changes: 40 additions & 116 deletions backend/src/api/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ export const acceptTerms = wrapHandler(async (event) => {
* description: List users.
* tags:
* - Users
*
*
*/
export const list = wrapHandler(async (event) => {
if (!isGlobalViewAdmin(event)) return Unauthorized;
Expand Down Expand Up @@ -511,16 +511,15 @@ export const getByRegionId = wrapHandler(async (event) => {
where: { regionId: regionId },
relations: ['roles', 'roles.organization']
});
if (result) {
if (result) {
return {
statusCode: 200,
body: JSON.stringify(result)
};
}
return NotFound;
return NotFound;
});


/**
* @swagger
*
Expand Down Expand Up @@ -548,10 +547,9 @@ export const getByState = wrapHandler(async (event) => {
body: JSON.stringify(result)
};
}
return NotFound;
return NotFound;
});


/**
* @swagger
*
Expand All @@ -564,28 +562,28 @@ export const getByState = wrapHandler(async (event) => {
export const register = wrapHandler(async (event) => {
const body = await validateBody(NewUser, event.body);
const newUser = {
"firstName": body.firstName,
"lastName": body.lastName,
"email": body.email.toLowerCase(),
"userType": UserType.STANDARD,
"state": body.state,
"regionId": REGION_STATE_MAP[body.state],
"invitePending": true,
}
console.log(JSON.stringify(newUser))
'firstName': body.firstName,

Check failure on line 565 in backend/src/api/users.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `'firstName'` with `firstName`
'lastName': body.lastName,

Check failure on line 566 in backend/src/api/users.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `'lastName'` with `lastName`
'email': body.email.toLowerCase(),

Check failure on line 567 in backend/src/api/users.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `'email'` with `email`
'userType': UserType.STANDARD,

Check failure on line 568 in backend/src/api/users.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `'userType'` with `userType`
'state': body.state,

Check failure on line 569 in backend/src/api/users.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `'state'` with `state`
'regionId': REGION_STATE_MAP[body.state],

Check failure on line 570 in backend/src/api/users.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `'regionId'` with `regionId`
'invitePending': true,

Check failure on line 571 in backend/src/api/users.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `'invitePending':·true,` with `invitePending:·true`
};
console.log(JSON.stringify(newUser));

await connectToDatabase();

// Check if user already exists
let userCheck = await User.findOne({
const userCheck = await User.findOne({
where: { email: newUser.email }
});

let id = "";
let id = '';
// Create if user does not exist
// if (!user) {
if (userCheck) {
console.log("User already exists.");
console.log('User already exists.');
return {
statusCode: 422,
body: 'User email already exists. Registration failed.'
Expand All @@ -603,10 +601,10 @@ export const register = wrapHandler(async (event) => {
// TODO: replace with html email function to user
sendUserNotificationEmail(
newUser.email,
"Crossfeed Registration Pending",
'Crossfeed Registration Pending',
newUser.firstName,

Check failure on line 605 in backend/src/api/users.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
newUser.lastName,
"/app/src/email_templates/crossfeed_registration_notification.html"
'/app/src/email_templates/crossfeed_registration_notification.html'
);
// Send new user pending approval email to regionalAdmin
// TODO: replace with html email function to regianlAdmin
Expand Down Expand Up @@ -656,27 +654,27 @@ export const registrationApproval = wrapHandler(async (event) => {
// UpdateUser,
// event.body
// );

// Connect to the database
await connectToDatabase();

Check failure on line 660 in backend/src/api/users.ts

View workflow job for this annotation

GitHub Actions / lint

Delete `·`
const user = await User.findOne(userId);
if (!user) {
return NotFound;
}

// Send email notification
sendUserNotificationEmail(user.email,

Check failure on line 667 in backend/src/api/users.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `user.email,·` with `⏎····user.email,`
"Crossfeed Registration Approved",
'Crossfeed Registration Approved',
user.firstName,
user.lastName,
"/app/src/email_templates/crossfeed_approval_notification.html");
'/app/src/email_templates/crossfeed_approval_notification.html');

// TODO: Handle Response Output
return {
statusCode: 200,
body: "User registration approved."
}
body: 'User registration approved.'
};
});

/**
Expand Down Expand Up @@ -722,11 +720,10 @@ export const registrationDenial = wrapHandler(async (event) => {
// TODO: Handle Response Output
return {
statusCode: 200,
body: "User registration denied."
}
body: 'User registration denied.'
};
});


//***************//
// V2 Endpoints //
//***************//
Expand All @@ -738,94 +735,62 @@ export const registrationDenial = wrapHandler(async (event) => {
* get:
* description: List all users with query parameters.
* tags:
* - Users
* - Users
* parameters:
* - in: query
* name: state
* required: false
* schema:
* type: array
* items:
* type: string
* type: string
* - in: query
* name: regionId
* required: false
* schema:
* type: array
* items:
* type: string
* type: string
* - in: query
* name: invitePending
* required: false
* schema:
* type: array
* items:
* type: string
*
* type: string
*
*/
export const getAllV2 = wrapHandler(async (event) => {
if (!isRegionalAdmin(event)) return Unauthorized;

const filterParams = {}
const filterParams = {};

if (event.query && event.query.state) {
filterParams["state"] = event.query.state;
filterParams['state'] = event.query.state;
}
if (event.query && event.query.regionId) {
filterParams["regionId"] = event.query.regionId;
filterParams['regionId'] = event.query.regionId;
}
if (event.query && event.query.invitePending) {
filterParams["invitePending"] = event.query.invitePending;
filterParams['invitePending'] = event.query.invitePending;
}

await connectToDatabase();
if (Object.entries(filterParams).length === 0) {
const result = await User.find({
relations: ['roles', 'roles.organization']
// relations: {
// roles: true,
// organizations: true
// },
});
return {
statusCode: 200,
body: JSON.stringify(result)
}
};
} else {
const result = await User.find({
where: filterParams,
relations: ['roles', 'roles.organization']
// relations: {
// roles: true,
// organizations: true
// },
// relations: {
// roles: {
// roles: true
// },
// organizations: {
// organizations: true
// }
// },
});
// const updatedResult = {
// ...result,
// numberOfOrganizations: 0,
// organizations: []
// }
// if (!result.roles) {
// result.roles = [];
// }
// updatedResult.roles.forEach((role) => {
// const org = role.organization;
// if (org) {
// updatedResult.numberOfOrganizations += 1;
// updatedResult.organizations.push(org);
// }
// });
return {
statusCode: 200,
// body: JSON.stringify(updatedResult)
body: JSON.stringify(result)
};
}
Expand Down Expand Up @@ -950,15 +915,6 @@ export const updateV2 = wrapHandler(async (event) => {
// Validate the body
const body = await validateBody(UpdateUser, event.body);

// User type permissions check
// if (!isRegionalAdmin(event)) return Unauthorized;

// // Validate the body
// const validatedBody = await validateBody(
// UpdateUser,
// event.body
// );

// Connect to the database
await connectToDatabase();

Expand All @@ -967,50 +923,18 @@ export const updateV2 = wrapHandler(async (event) => {
return NotFound;
}

// TODO: check permissions
// if (!isOrgAdmin(event, id)) return Unauthorized;

// If organization id is supplied, create approved role
// if (body.organization) {
// // Check if organization exists
// const organization = await Organization.findOne(body.organization);
// if (organization) {
// // Create approved role if organization supplied
// await Role.createQueryBuilder()
// .insert()
// .values({
// user: user,
// oganization: organization,
// approved: true,
// createdBy: { id: event.requestContext.authorizer!.id },
// approvedBy: { id: event.requestContext.authorizer!.id },
// role: "user"
// })
// .onConflict(
// `
// ("userId", "organizationId") DO UPDATE
// SET "role" = excluded."role",
// "approved" = excluded."approved",
// "approvedById" = excluded."approvedById"
// `
// )
// .execute();
// }
// }

// Update the user
const updatedResp = await User.update(userId, body);

// Handle response
if (updatedResp) {
const updatedUser = await User.findOne(
userId,
{ relations: ['roles', 'roles.organization'] }
);
const updatedUser = await User.findOne(userId, {
relations: ['roles', 'roles.organization']
});
return {
statusCode: 200,
body: JSON.stringify(updatedUser)
};
}
return NotFound;
});
});

0 comments on commit 1a5911f

Please sign in to comment.