From 726f14331badfad42429a516d33468b1ce13b9b9 Mon Sep 17 00:00:00 2001 From: Ryan Ding Date: Wed, 21 Feb 2024 16:48:51 -0800 Subject: [PATCH 01/17] Add names to retroactive attendance form --- repositories/UserRepository.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/repositories/UserRepository.ts b/repositories/UserRepository.ts index 17f32ebae..6f5e6539c 100644 --- a/repositories/UserRepository.ts +++ b/repositories/UserRepository.ts @@ -48,9 +48,9 @@ export class UserRepository extends BaseRepository { public async getAllEmails(): Promise { const emailsRaw = await this.repository .createQueryBuilder() - .select('email') + .select(['email', 'UserModel.firstName', 'UserModel.lastName']) .getRawMany(); - return emailsRaw.map((emailRaw) => emailRaw.email); + return emailsRaw.map((emailRaw) => `${emailRaw.UserModel_firstName} ${emailRaw.UserModel_lastName} - ${emailRaw.email}`); } public static async generateHash(pass: string): Promise { From fb902e9106a9e3494cf6b432b383149cdc5b8d63 Mon Sep 17 00:00:00 2001 From: ryanDing26 <110417507+ryanDing26@users.noreply.github.com> Date: Mon, 25 Mar 2024 16:07:28 -0700 Subject: [PATCH 02/17] Fix tests, rename email method --- api/controllers/AdminController.ts | 8 ++++---- repositories/UserRepository.ts | 7 ++++--- services/UserAccountService.ts | 5 +++-- tests/admin.test.ts | 9 +++++---- types/ApiResponses.ts | 4 ++-- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/api/controllers/AdminController.ts b/api/controllers/AdminController.ts index 6ab761084..56107c1b4 100644 --- a/api/controllers/AdminController.ts +++ b/api/controllers/AdminController.ts @@ -12,7 +12,7 @@ import { CreateMilestoneResponse, CreateBonusResponse, UploadBannerResponse, - GetAllEmailsResponse, + GetAllNamesEmailsResponse, SubmitAttendanceForUsersResponse, ModifyUserAccessLevelResponse, GetAllUserAccessLevelsResponse, @@ -41,10 +41,10 @@ export class AdminController { } @Get('/email') - async getAllEmails(@AuthenticatedUser() user: UserModel): Promise { + async getAllNamesEmails(@AuthenticatedUser() user: UserModel): Promise { if (!PermissionsService.canSeeAllUserEmails(user)) throw new ForbiddenError(); - const emails = await this.userAccountService.getAllEmails(); - return { error: null, emails }; + const namesEmails = await this.userAccountService.getAllNamesEmails(); + return { error: null, namesEmails }; } @Post('/milestone') diff --git a/repositories/UserRepository.ts b/repositories/UserRepository.ts index 6f5e6539c..7e2a79a5c 100644 --- a/repositories/UserRepository.ts +++ b/repositories/UserRepository.ts @@ -45,12 +45,13 @@ export class UserRepository extends BaseRepository { return this.repository.findOne({ accessCode }); } - public async getAllEmails(): Promise { - const emailsRaw = await this.repository + public async getAllNamesEmails(): Promise { + const namesEmailsRaw = await this.repository .createQueryBuilder() .select(['email', 'UserModel.firstName', 'UserModel.lastName']) .getRawMany(); - return emailsRaw.map((emailRaw) => `${emailRaw.UserModel_firstName} ${emailRaw.UserModel_lastName} - ${emailRaw.email}`); + return namesEmailsRaw.map((nameEmailRaw)=> + `${nameEmailRaw.UserModel_firstName} ${nameEmailRaw.UserModel_lastName} (${nameEmailRaw.email})`); } public static async generateHash(pass: string): Promise { diff --git a/services/UserAccountService.ts b/services/UserAccountService.ts index 3a17d175b..ec3f714b8 100644 --- a/services/UserAccountService.ts +++ b/services/UserAccountService.ts @@ -15,6 +15,7 @@ import { UserPatches, UserState, PrivateProfile, + GetAllNamesEmailsResponse, } from '../types'; import { UserRepository } from '../repositories/UserRepository'; import { UserModel } from '../models/UserModel'; @@ -167,10 +168,10 @@ export default class UserAccountService { }); } - public async getAllEmails(): Promise { + public async getAllNamesEmails(): Promise { return this.transactions.readOnly(async (txn) => Repositories .user(txn) - .getAllEmails()); + .getAllNamesEmails()); } /** diff --git a/tests/admin.test.ts b/tests/admin.test.ts index 021f8c6d1..9e3629900 100644 --- a/tests/admin.test.ts +++ b/tests/admin.test.ts @@ -131,19 +131,20 @@ describe('retroactive attendance submission', () => { }); }); -describe('email retrieval', () => { +describe('names and emails retrieval', () => { test('gets all the emails of stored users', async () => { const conn = await DatabaseConnection.get(); const users = UserFactory.create(5); - const emails = users.map((user) => user.email.toLowerCase()); + const namesEmails = users.map((user) => `${user.firstName} ${user.lastName} (${user.email.toLowerCase()})`); const admin = UserFactory.fake({ accessType: UserAccessType.ADMIN }); await new PortalState() .createUsers(...users, admin) .write(); - const response = await ControllerFactory.admin(conn).getAllEmails(admin); - expect(expect.arrayContaining(response.emails)).toEqual([...emails, admin.email]); + const response = await ControllerFactory.admin(conn).getAllNamesEmails(admin); + expect(expect.arrayContaining(response.namesEmails)).toEqual([...namesEmails, + `${admin.firstName} ${admin.lastName} (${admin.email})`]); }); }); diff --git a/types/ApiResponses.ts b/types/ApiResponses.ts index cb93f0469..e342c3084 100644 --- a/types/ApiResponses.ts +++ b/types/ApiResponses.ts @@ -31,8 +31,8 @@ export interface UploadBannerResponse extends ApiResponse { banner: string; } -export interface GetAllEmailsResponse extends ApiResponse { - emails: string[]; +export interface GetAllNamesEmailsResponse extends ApiResponse { + namesEmails: string[]; } export interface SubmitAttendanceForUsersResponse extends ApiResponse { From cfe34e319f87bb3dee006996c29f868b0b42396a Mon Sep 17 00:00:00 2001 From: ryanDing26 <110417507+ryanDing26@users.noreply.github.com> Date: Mon, 25 Mar 2024 16:10:25 -0700 Subject: [PATCH 03/17] Fix lint tests --- repositories/UserRepository.ts | 4 ++-- services/UserAccountService.ts | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/repositories/UserRepository.ts b/repositories/UserRepository.ts index 7e2a79a5c..45832c65d 100644 --- a/repositories/UserRepository.ts +++ b/repositories/UserRepository.ts @@ -50,8 +50,8 @@ export class UserRepository extends BaseRepository { .createQueryBuilder() .select(['email', 'UserModel.firstName', 'UserModel.lastName']) .getRawMany(); - return namesEmailsRaw.map((nameEmailRaw)=> - `${nameEmailRaw.UserModel_firstName} ${nameEmailRaw.UserModel_lastName} (${nameEmailRaw.email})`); + return namesEmailsRaw.map((nameEmailRaw) => + `${nameEmailRaw.UserModel_firstName} ${nameEmailRaw.UserModel_lastName} (${nameEmailRaw.email})`); } public static async generateHash(pass: string): Promise { diff --git a/services/UserAccountService.ts b/services/UserAccountService.ts index ec3f714b8..fbec7924f 100644 --- a/services/UserAccountService.ts +++ b/services/UserAccountService.ts @@ -14,8 +14,7 @@ import { Milestone, UserPatches, UserState, - PrivateProfile, - GetAllNamesEmailsResponse, + PrivateProfile } from '../types'; import { UserRepository } from '../repositories/UserRepository'; import { UserModel } from '../models/UserModel'; From b524e8cc0f469ddb1c161f4849ed18f14ac53a95 Mon Sep 17 00:00:00 2001 From: ryanDing26 <110417507+ryanDing26@users.noreply.github.com> Date: Mon, 25 Mar 2024 16:22:23 -0700 Subject: [PATCH 04/17] Fixed linter issues except for one --- repositories/UserRepository.ts | 3 +-- services/UserAccountService.ts | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/repositories/UserRepository.ts b/repositories/UserRepository.ts index 45832c65d..fc9586d6e 100644 --- a/repositories/UserRepository.ts +++ b/repositories/UserRepository.ts @@ -50,8 +50,7 @@ export class UserRepository extends BaseRepository { .createQueryBuilder() .select(['email', 'UserModel.firstName', 'UserModel.lastName']) .getRawMany(); - return namesEmailsRaw.map((nameEmailRaw) => - `${nameEmailRaw.UserModel_firstName} ${nameEmailRaw.UserModel_lastName} (${nameEmailRaw.email})`); + return namesEmailsRaw.map((nameEmailRaw) => `${nameEmailRaw.UserModel_firstName} ${nameEmailRaw.UserModel_lastName} (${nameEmailRaw.email})`); } public static async generateHash(pass: string): Promise { diff --git a/services/UserAccountService.ts b/services/UserAccountService.ts index fbec7924f..885a1a48b 100644 --- a/services/UserAccountService.ts +++ b/services/UserAccountService.ts @@ -14,7 +14,7 @@ import { Milestone, UserPatches, UserState, - PrivateProfile + PrivateProfile, } from '../types'; import { UserRepository } from '../repositories/UserRepository'; import { UserModel } from '../models/UserModel'; From cab5a90291c9cb99392db6e105a24e095222a2eb Mon Sep 17 00:00:00 2001 From: "Caogang (Marcelo) Shen" Date: Wed, 27 Mar 2024 20:58:50 -0700 Subject: [PATCH 05/17] Update UserRepository.ts See if this do --- repositories/UserRepository.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/repositories/UserRepository.ts b/repositories/UserRepository.ts index fc9586d6e..d93ba6eb4 100644 --- a/repositories/UserRepository.ts +++ b/repositories/UserRepository.ts @@ -50,7 +50,8 @@ export class UserRepository extends BaseRepository { .createQueryBuilder() .select(['email', 'UserModel.firstName', 'UserModel.lastName']) .getRawMany(); - return namesEmailsRaw.map((nameEmailRaw) => `${nameEmailRaw.UserModel_firstName} ${nameEmailRaw.UserModel_lastName} (${nameEmailRaw.email})`); + return namesEmailsRaw.map((nameEmailRaw) => + `${nameEmailRaw.UserModel_firstName} ${nameEmailRaw.UserModel_lastName} (${nameEmailRaw.email})`); } public static async generateHash(pass: string): Promise { From 9e941171f0384fb64916f2c5b6b76ecae1544b65 Mon Sep 17 00:00:00 2001 From: Marcelo Shen Date: Wed, 27 Mar 2024 21:04:55 -0700 Subject: [PATCH 06/17] No but this works --- repositories/UserRepository.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/repositories/UserRepository.ts b/repositories/UserRepository.ts index d93ba6eb4..52a0dfc15 100644 --- a/repositories/UserRepository.ts +++ b/repositories/UserRepository.ts @@ -50,8 +50,8 @@ export class UserRepository extends BaseRepository { .createQueryBuilder() .select(['email', 'UserModel.firstName', 'UserModel.lastName']) .getRawMany(); - return namesEmailsRaw.map((nameEmailRaw) => - `${nameEmailRaw.UserModel_firstName} ${nameEmailRaw.UserModel_lastName} (${nameEmailRaw.email})`); + return namesEmailsRaw.map((nameEmailRaw) => `${nameEmailRaw.UserModel_firstName} ` + + `${nameEmailRaw.UserModel_lastName} (${nameEmailRaw.email})`); } public static async generateHash(pass: string): Promise { From ce4d7272c4494abf30fc1dbfb150f8d8ffb3cb0f Mon Sep 17 00:00:00 2001 From: Marcelo Shen Date: Wed, 27 Mar 2024 21:35:44 -0700 Subject: [PATCH 07/17] this should work v2 --- repositories/UserRepository.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/repositories/UserRepository.ts b/repositories/UserRepository.ts index 52a0dfc15..4dc966eda 100644 --- a/repositories/UserRepository.ts +++ b/repositories/UserRepository.ts @@ -50,8 +50,8 @@ export class UserRepository extends BaseRepository { .createQueryBuilder() .select(['email', 'UserModel.firstName', 'UserModel.lastName']) .getRawMany(); - return namesEmailsRaw.map((nameEmailRaw) => `${nameEmailRaw.UserModel_firstName} ` + - `${nameEmailRaw.UserModel_lastName} (${nameEmailRaw.email})`); + return namesEmailsRaw.map((nameEmailRaw) => `${nameEmailRaw.UserModel_firstName} ` + + `${nameEmailRaw.UserModel_lastName} (${nameEmailRaw.email})`); } public static async generateHash(pass: string): Promise { From 78073ac8de222bfd2435f47fefe658aea1a7a42d Mon Sep 17 00:00:00 2001 From: ryanDing26 <110417507+ryanDing26@users.noreply.github.com> Date: Mon, 1 Apr 2024 16:21:49 -0700 Subject: [PATCH 08/17] New type for names and email yipee --- repositories/UserRepository.ts | 12 +++++++++--- services/UserAccountService.ts | 2 +- types/ApiResponses.ts | 9 ++++++++- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/repositories/UserRepository.ts b/repositories/UserRepository.ts index 4dc966eda..bc7d69c31 100644 --- a/repositories/UserRepository.ts +++ b/repositories/UserRepository.ts @@ -5,6 +5,9 @@ import { UserModel } from '../models/UserModel'; import { Uuid } from '../types'; import { BaseRepository } from './BaseRepository'; +// Temporary interface import location in ApiResponses.ts +import { NameEmail } from '../types/ApiResponses'; + @EntityRepository(UserModel) export class UserRepository extends BaseRepository { private static readonly SALT_ROUNDS = 10; @@ -45,13 +48,16 @@ export class UserRepository extends BaseRepository { return this.repository.findOne({ accessCode }); } - public async getAllNamesEmails(): Promise { + public async getAllNamesEmails(): Promise { const namesEmailsRaw = await this.repository .createQueryBuilder() .select(['email', 'UserModel.firstName', 'UserModel.lastName']) .getRawMany(); - return namesEmailsRaw.map((nameEmailRaw) => `${nameEmailRaw.UserModel_firstName} ` - + `${nameEmailRaw.UserModel_lastName} (${nameEmailRaw.email})`); + const nameEmailFormatted: NameEmail[] = namesEmailsRaw.map((nameEmailRaw) => + ({firstName: nameEmailRaw.UserModel_firstName, + lastName: nameEmailRaw.UserModel_lastName, + email: nameEmailRaw.email})); + return nameEmailFormatted; } public static async generateHash(pass: string): Promise { diff --git a/services/UserAccountService.ts b/services/UserAccountService.ts index 885a1a48b..ab72b77c9 100644 --- a/services/UserAccountService.ts +++ b/services/UserAccountService.ts @@ -167,7 +167,7 @@ export default class UserAccountService { }); } - public async getAllNamesEmails(): Promise { + public async getAllNamesEmails() { return this.transactions.readOnly(async (txn) => Repositories .user(txn) .getAllNamesEmails()); diff --git a/types/ApiResponses.ts b/types/ApiResponses.ts index e342c3084..eb542eb12 100644 --- a/types/ApiResponses.ts +++ b/types/ApiResponses.ts @@ -7,6 +7,13 @@ import { MerchItemOptionMetadata, Uuid } from '.'; // RESPONSE TYPES +// Please remove this when it is figured out where to put the new object type: +export interface NameEmail { + firstName: string; + lastName: string; + email: string; +} + export interface CustomErrorBody { name: string; message: string; @@ -32,7 +39,7 @@ export interface UploadBannerResponse extends ApiResponse { } export interface GetAllNamesEmailsResponse extends ApiResponse { - namesEmails: string[]; + namesEmails: NameEmail[]; } export interface SubmitAttendanceForUsersResponse extends ApiResponse { From a035fde295b547f2aa867843a1c9dd8e6413fbda Mon Sep 17 00:00:00 2001 From: ryanDing26 <110417507+ryanDing26@users.noreply.github.com> Date: Mon, 1 Apr 2024 16:37:40 -0700 Subject: [PATCH 09/17] Fixed tests to go along with changes --- repositories/UserRepository.ts | 7 +++---- tests/admin.test.ts | 8 ++++++-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/repositories/UserRepository.ts b/repositories/UserRepository.ts index bc7d69c31..365966599 100644 --- a/repositories/UserRepository.ts +++ b/repositories/UserRepository.ts @@ -53,10 +53,9 @@ export class UserRepository extends BaseRepository { .createQueryBuilder() .select(['email', 'UserModel.firstName', 'UserModel.lastName']) .getRawMany(); - const nameEmailFormatted: NameEmail[] = namesEmailsRaw.map((nameEmailRaw) => - ({firstName: nameEmailRaw.UserModel_firstName, - lastName: nameEmailRaw.UserModel_lastName, - email: nameEmailRaw.email})); + const nameEmailFormatted: NameEmail[] = namesEmailsRaw.map((nameEmailRaw) => ({ firstName: nameEmailRaw.UserModel_firstName, + lastName: nameEmailRaw.UserModel_lastName, + email: nameEmailRaw.email })); return nameEmailFormatted; } diff --git a/tests/admin.test.ts b/tests/admin.test.ts index 9e3629900..d945dbc91 100644 --- a/tests/admin.test.ts +++ b/tests/admin.test.ts @@ -5,6 +5,9 @@ import { ControllerFactory } from './controllers'; import { DatabaseConnection, EventFactory, PortalState, UserFactory } from './data'; import { UserModel } from '../models/UserModel'; +// Remove when relocation is done perhaps +import { NameEmail } from '../types/ApiResponses'; + beforeAll(async () => { await DatabaseConnection.connect(); }); @@ -135,7 +138,7 @@ describe('names and emails retrieval', () => { test('gets all the emails of stored users', async () => { const conn = await DatabaseConnection.get(); const users = UserFactory.create(5); - const namesEmails = users.map((user) => `${user.firstName} ${user.lastName} (${user.email.toLowerCase()})`); + const namesEmails: NameEmail[] = users.map((user) => ({ firstName: user.firstName, lastName: user.lastName, email: user.email.toLowerCase() })); const admin = UserFactory.fake({ accessType: UserAccessType.ADMIN }); await new PortalState() @@ -143,8 +146,9 @@ describe('names and emails retrieval', () => { .write(); const response = await ControllerFactory.admin(conn).getAllNamesEmails(admin); + const expected: NameEmail = { firstName: admin.firstName, lastName: admin.lastName, email: admin.email }; expect(expect.arrayContaining(response.namesEmails)).toEqual([...namesEmails, - `${admin.firstName} ${admin.lastName} (${admin.email})`]); + expected]); }); }); From 5b3270c81c3060aa7de9c696ea0f8ce8c0206a50 Mon Sep 17 00:00:00 2001 From: ryanDing26 <110417507+ryanDing26@users.noreply.github.com> Date: Tue, 2 Apr 2024 02:33:36 -0700 Subject: [PATCH 10/17] Let lint do magic --- repositories/UserRepository.ts | 12 +++++------- tests/admin.test.ts | 10 +++++----- types/ApiResponses.ts | 13 +++++-------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/repositories/UserRepository.ts b/repositories/UserRepository.ts index 365966599..87b2dabf3 100644 --- a/repositories/UserRepository.ts +++ b/repositories/UserRepository.ts @@ -2,12 +2,9 @@ import { EntityRepository, In } from 'typeorm'; import * as bcrypt from 'bcrypt'; import { Activity } from '../types/internal'; import { UserModel } from '../models/UserModel'; -import { Uuid } from '../types'; +import { Uuid, NameEmail } from '../types'; import { BaseRepository } from './BaseRepository'; -// Temporary interface import location in ApiResponses.ts -import { NameEmail } from '../types/ApiResponses'; - @EntityRepository(UserModel) export class UserRepository extends BaseRepository { private static readonly SALT_ROUNDS = 10; @@ -53,9 +50,10 @@ export class UserRepository extends BaseRepository { .createQueryBuilder() .select(['email', 'UserModel.firstName', 'UserModel.lastName']) .getRawMany(); - const nameEmailFormatted: NameEmail[] = namesEmailsRaw.map((nameEmailRaw) => ({ firstName: nameEmailRaw.UserModel_firstName, - lastName: nameEmailRaw.UserModel_lastName, - email: nameEmailRaw.email })); + const nameEmailFormatted: NameEmail[] = namesEmailsRaw.map((nameEmailRaw) => ({ firstName: + nameEmailRaw.UserModel_firstName, + lastName: nameEmailRaw.UserModel_lastName, + email: nameEmailRaw.email })); return nameEmailFormatted; } diff --git a/tests/admin.test.ts b/tests/admin.test.ts index d945dbc91..48305cdaf 100644 --- a/tests/admin.test.ts +++ b/tests/admin.test.ts @@ -1,13 +1,10 @@ import { BadRequestError, ForbiddenError } from 'routing-controllers'; import { In } from 'typeorm'; -import { ActivityScope, ActivityType, SubmitAttendanceForUsersRequest, UserAccessType } from '../types'; +import { ActivityScope, ActivityType, SubmitAttendanceForUsersRequest, UserAccessType, NameEmail } from '../types'; import { ControllerFactory } from './controllers'; import { DatabaseConnection, EventFactory, PortalState, UserFactory } from './data'; import { UserModel } from '../models/UserModel'; -// Remove when relocation is done perhaps -import { NameEmail } from '../types/ApiResponses'; - beforeAll(async () => { await DatabaseConnection.connect(); }); @@ -138,7 +135,10 @@ describe('names and emails retrieval', () => { test('gets all the emails of stored users', async () => { const conn = await DatabaseConnection.get(); const users = UserFactory.create(5); - const namesEmails: NameEmail[] = users.map((user) => ({ firstName: user.firstName, lastName: user.lastName, email: user.email.toLowerCase() })); + const namesEmails: NameEmail[] = users.map((user) => ({ firstName: user.firstName, + lastName: user.lastName, + email: + user.email.toLowerCase() })); const admin = UserFactory.fake({ accessType: UserAccessType.ADMIN }); await new PortalState() diff --git a/types/ApiResponses.ts b/types/ApiResponses.ts index eb542eb12..5e0e37d0e 100644 --- a/types/ApiResponses.ts +++ b/types/ApiResponses.ts @@ -6,14 +6,6 @@ import { import { MerchItemOptionMetadata, Uuid } from '.'; // RESPONSE TYPES - -// Please remove this when it is figured out where to put the new object type: -export interface NameEmail { - firstName: string; - lastName: string; - email: string; -} - export interface CustomErrorBody { name: string; message: string; @@ -306,6 +298,11 @@ export interface FulfillMerchOrderResponse extends ApiResponse { } // USER +export interface NameEmail { + firstName: string; + lastName: string; + email: string; +} export interface PublicActivity { type: ActivityType, From 15f93b533253b7660ad6052759ea6bfa485af3c9 Mon Sep 17 00:00:00 2001 From: ryanDing26 <110417507+ryanDing26@users.noreply.github.com> Date: Wed, 24 Apr 2024 12:09:49 -0700 Subject: [PATCH 11/17] Fix nits --- repositories/UserRepository.ts | 2 +- services/UserAccountService.ts | 2 +- types/ApiResponses.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/repositories/UserRepository.ts b/repositories/UserRepository.ts index 87b2dabf3..0a525fe43 100644 --- a/repositories/UserRepository.ts +++ b/repositories/UserRepository.ts @@ -45,7 +45,7 @@ export class UserRepository extends BaseRepository { return this.repository.findOne({ accessCode }); } - public async getAllNamesEmails(): Promise { + public async getAllNamesAndEmails(): Promise { const namesEmailsRaw = await this.repository .createQueryBuilder() .select(['email', 'UserModel.firstName', 'UserModel.lastName']) diff --git a/services/UserAccountService.ts b/services/UserAccountService.ts index ab72b77c9..438adcbd3 100644 --- a/services/UserAccountService.ts +++ b/services/UserAccountService.ts @@ -167,7 +167,7 @@ export default class UserAccountService { }); } - public async getAllNamesEmails() { + public async getAllNamesAndEmails() { return this.transactions.readOnly(async (txn) => Repositories .user(txn) .getAllNamesEmails()); diff --git a/types/ApiResponses.ts b/types/ApiResponses.ts index 5e0e37d0e..41c2537e2 100644 --- a/types/ApiResponses.ts +++ b/types/ApiResponses.ts @@ -298,7 +298,7 @@ export interface FulfillMerchOrderResponse extends ApiResponse { } // USER -export interface NameEmail { +export interface NameAndEmail { firstName: string; lastName: string; email: string; From 1dd91635f99693919658e817cee116683f64588e Mon Sep 17 00:00:00 2001 From: ryanDing26 <110417507+ryanDing26@users.noreply.github.com> Date: Wed, 24 Apr 2024 12:11:53 -0700 Subject: [PATCH 12/17] Forgot to fix tests/var changes --- repositories/UserRepository.ts | 6 +++--- services/UserAccountService.ts | 2 +- tests/admin.test.ts | 6 +++--- types/ApiResponses.ts | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/repositories/UserRepository.ts b/repositories/UserRepository.ts index 0a525fe43..0f23094c4 100644 --- a/repositories/UserRepository.ts +++ b/repositories/UserRepository.ts @@ -2,7 +2,7 @@ import { EntityRepository, In } from 'typeorm'; import * as bcrypt from 'bcrypt'; import { Activity } from '../types/internal'; import { UserModel } from '../models/UserModel'; -import { Uuid, NameEmail } from '../types'; +import { Uuid, NameAndEmail } from '../types'; import { BaseRepository } from './BaseRepository'; @EntityRepository(UserModel) @@ -45,12 +45,12 @@ export class UserRepository extends BaseRepository { return this.repository.findOne({ accessCode }); } - public async getAllNamesAndEmails(): Promise { + public async getAllNamesAndEmails(): Promise { const namesEmailsRaw = await this.repository .createQueryBuilder() .select(['email', 'UserModel.firstName', 'UserModel.lastName']) .getRawMany(); - const nameEmailFormatted: NameEmail[] = namesEmailsRaw.map((nameEmailRaw) => ({ firstName: + const nameEmailFormatted: NameAndEmail[] = namesEmailsRaw.map((nameEmailRaw) => ({ firstName: nameEmailRaw.UserModel_firstName, lastName: nameEmailRaw.UserModel_lastName, email: nameEmailRaw.email })); diff --git a/services/UserAccountService.ts b/services/UserAccountService.ts index 438adcbd3..3c46b7869 100644 --- a/services/UserAccountService.ts +++ b/services/UserAccountService.ts @@ -170,7 +170,7 @@ export default class UserAccountService { public async getAllNamesAndEmails() { return this.transactions.readOnly(async (txn) => Repositories .user(txn) - .getAllNamesEmails()); + .getAllNamesAndEmails()); } /** diff --git a/tests/admin.test.ts b/tests/admin.test.ts index 48305cdaf..46c9a365c 100644 --- a/tests/admin.test.ts +++ b/tests/admin.test.ts @@ -1,6 +1,6 @@ import { BadRequestError, ForbiddenError } from 'routing-controllers'; import { In } from 'typeorm'; -import { ActivityScope, ActivityType, SubmitAttendanceForUsersRequest, UserAccessType, NameEmail } from '../types'; +import { ActivityScope, ActivityType, SubmitAttendanceForUsersRequest, UserAccessType, NameAndEmail } from '../types'; import { ControllerFactory } from './controllers'; import { DatabaseConnection, EventFactory, PortalState, UserFactory } from './data'; import { UserModel } from '../models/UserModel'; @@ -135,7 +135,7 @@ describe('names and emails retrieval', () => { test('gets all the emails of stored users', async () => { const conn = await DatabaseConnection.get(); const users = UserFactory.create(5); - const namesEmails: NameEmail[] = users.map((user) => ({ firstName: user.firstName, + const namesEmails: NameAndEmail[] = users.map((user) => ({ firstName: user.firstName, lastName: user.lastName, email: user.email.toLowerCase() })); @@ -146,7 +146,7 @@ describe('names and emails retrieval', () => { .write(); const response = await ControllerFactory.admin(conn).getAllNamesEmails(admin); - const expected: NameEmail = { firstName: admin.firstName, lastName: admin.lastName, email: admin.email }; + const expected: NameAndEmail = { firstName: admin.firstName, lastName: admin.lastName, email: admin.email }; expect(expect.arrayContaining(response.namesEmails)).toEqual([...namesEmails, expected]); }); diff --git a/types/ApiResponses.ts b/types/ApiResponses.ts index 41c2537e2..385335801 100644 --- a/types/ApiResponses.ts +++ b/types/ApiResponses.ts @@ -31,7 +31,7 @@ export interface UploadBannerResponse extends ApiResponse { } export interface GetAllNamesEmailsResponse extends ApiResponse { - namesEmails: NameEmail[]; + namesEmails: NameAndEmail[]; } export interface SubmitAttendanceForUsersResponse extends ApiResponse { From 7b1dbb46cb112d4371a57542920423106bea9e20 Mon Sep 17 00:00:00 2001 From: ryanDing26 <110417507+ryanDing26@users.noreply.github.com> Date: Wed, 24 Apr 2024 12:18:31 -0700 Subject: [PATCH 13/17] bruh --- api/controllers/AdminController.ts | 6 +++--- tests/admin.test.ts | 2 +- types/ApiResponses.ts | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/api/controllers/AdminController.ts b/api/controllers/AdminController.ts index 56107c1b4..15e5c503b 100644 --- a/api/controllers/AdminController.ts +++ b/api/controllers/AdminController.ts @@ -12,7 +12,7 @@ import { CreateMilestoneResponse, CreateBonusResponse, UploadBannerResponse, - GetAllNamesEmailsResponse, + GetAllNamesAndEmailsResponse, SubmitAttendanceForUsersResponse, ModifyUserAccessLevelResponse, GetAllUserAccessLevelsResponse, @@ -41,9 +41,9 @@ export class AdminController { } @Get('/email') - async getAllNamesEmails(@AuthenticatedUser() user: UserModel): Promise { + async getAllNamesAndEmails(@AuthenticatedUser() user: UserModel): Promise { if (!PermissionsService.canSeeAllUserEmails(user)) throw new ForbiddenError(); - const namesEmails = await this.userAccountService.getAllNamesEmails(); + const namesEmails = await this.userAccountService.getAllNamesAndEmails(); return { error: null, namesEmails }; } diff --git a/tests/admin.test.ts b/tests/admin.test.ts index 46c9a365c..9ad7a8650 100644 --- a/tests/admin.test.ts +++ b/tests/admin.test.ts @@ -145,7 +145,7 @@ describe('names and emails retrieval', () => { .createUsers(...users, admin) .write(); - const response = await ControllerFactory.admin(conn).getAllNamesEmails(admin); + const response = await ControllerFactory.admin(conn).getAllNamesAndEmails(admin); const expected: NameAndEmail = { firstName: admin.firstName, lastName: admin.lastName, email: admin.email }; expect(expect.arrayContaining(response.namesEmails)).toEqual([...namesEmails, expected]); diff --git a/types/ApiResponses.ts b/types/ApiResponses.ts index 385335801..fe2db67dc 100644 --- a/types/ApiResponses.ts +++ b/types/ApiResponses.ts @@ -30,7 +30,7 @@ export interface UploadBannerResponse extends ApiResponse { banner: string; } -export interface GetAllNamesEmailsResponse extends ApiResponse { +export interface GetAllNamesAndEmailsResponse extends ApiResponse { namesEmails: NameAndEmail[]; } From 83139940fd703498f00557925ade625a5079139f Mon Sep 17 00:00:00 2001 From: ryanDing26 <110417507+ryanDing26@users.noreply.github.com> Date: Wed, 24 Apr 2024 15:18:34 -0700 Subject: [PATCH 14/17] what --- api/controllers/AdminController.ts | 4 ++-- repositories/UserRepository.ts | 12 ++++++------ types/ApiResponses.ts | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/api/controllers/AdminController.ts b/api/controllers/AdminController.ts index 15e5c503b..b1fb41c21 100644 --- a/api/controllers/AdminController.ts +++ b/api/controllers/AdminController.ts @@ -43,8 +43,8 @@ export class AdminController { @Get('/email') async getAllNamesAndEmails(@AuthenticatedUser() user: UserModel): Promise { if (!PermissionsService.canSeeAllUserEmails(user)) throw new ForbiddenError(); - const namesEmails = await this.userAccountService.getAllNamesAndEmails(); - return { error: null, namesEmails }; + const namesAndEmails = await this.userAccountService.getAllNamesAndEmails(); + return { error: null, namesAndEmails }; } @Post('/milestone') diff --git a/repositories/UserRepository.ts b/repositories/UserRepository.ts index 0f23094c4..1e174f409 100644 --- a/repositories/UserRepository.ts +++ b/repositories/UserRepository.ts @@ -46,15 +46,15 @@ export class UserRepository extends BaseRepository { } public async getAllNamesAndEmails(): Promise { - const namesEmailsRaw = await this.repository + const namesAndEmailsRaw = await this.repository .createQueryBuilder() .select(['email', 'UserModel.firstName', 'UserModel.lastName']) .getRawMany(); - const nameEmailFormatted: NameAndEmail[] = namesEmailsRaw.map((nameEmailRaw) => ({ firstName: - nameEmailRaw.UserModel_firstName, - lastName: nameEmailRaw.UserModel_lastName, - email: nameEmailRaw.email })); - return nameEmailFormatted; + const namesAndEmailsFormatted: NameAndEmail[] = namesAndEmailsRaw.map((nameAndEmailRaw) => ({ firstName: + nameAndEmailRaw.UserModel_firstName, + lastName: nameAndEmailRaw.UserModel_lastName, + email: nameAndEmailRaw.email })); + return namesAndEmailsFormatted; } public static async generateHash(pass: string): Promise { diff --git a/types/ApiResponses.ts b/types/ApiResponses.ts index fe2db67dc..3bd9bfcd1 100644 --- a/types/ApiResponses.ts +++ b/types/ApiResponses.ts @@ -31,7 +31,7 @@ export interface UploadBannerResponse extends ApiResponse { } export interface GetAllNamesAndEmailsResponse extends ApiResponse { - namesEmails: NameAndEmail[]; + namesAndEmails: NameAndEmail[]; } export interface SubmitAttendanceForUsersResponse extends ApiResponse { From e98764a2db00681247741074b0cf5f5a7d1d4ad8 Mon Sep 17 00:00:00 2001 From: ryanDing26 <110417507+ryanDing26@users.noreply.github.com> Date: Wed, 24 Apr 2024 15:20:46 -0700 Subject: [PATCH 15/17] what again --- tests/admin.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/admin.test.ts b/tests/admin.test.ts index 9ad7a8650..77863540a 100644 --- a/tests/admin.test.ts +++ b/tests/admin.test.ts @@ -135,7 +135,7 @@ describe('names and emails retrieval', () => { test('gets all the emails of stored users', async () => { const conn = await DatabaseConnection.get(); const users = UserFactory.create(5); - const namesEmails: NameAndEmail[] = users.map((user) => ({ firstName: user.firstName, + const namesAndEmails: NameAndEmail[] = users.map((user) => ({ firstName: user.firstName, lastName: user.lastName, email: user.email.toLowerCase() })); @@ -147,7 +147,7 @@ describe('names and emails retrieval', () => { const response = await ControllerFactory.admin(conn).getAllNamesAndEmails(admin); const expected: NameAndEmail = { firstName: admin.firstName, lastName: admin.lastName, email: admin.email }; - expect(expect.arrayContaining(response.namesEmails)).toEqual([...namesEmails, + expect(expect.arrayContaining(response.namesAndEmails)).toEqual([...namesAndEmails, expected]); }); }); From 99f0399f9401b9a3d6ce477b9b631464f9b87cf5 Mon Sep 17 00:00:00 2001 From: Nikhil Dange Date: Mon, 29 Apr 2024 19:24:39 -0700 Subject: [PATCH 16/17] added type --- services/UserAccountService.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/services/UserAccountService.ts b/services/UserAccountService.ts index 3c46b7869..d5f884183 100644 --- a/services/UserAccountService.ts +++ b/services/UserAccountService.ts @@ -15,9 +15,11 @@ import { UserPatches, UserState, PrivateProfile, + NameAndEmail } from '../types'; import { UserRepository } from '../repositories/UserRepository'; import { UserModel } from '../models/UserModel'; +import { Name } from 'aws-sdk/clients/appstream'; @Service() export default class UserAccountService { @@ -167,7 +169,7 @@ export default class UserAccountService { }); } - public async getAllNamesAndEmails() { + public async getAllNamesAndEmails(): Promise { return this.transactions.readOnly(async (txn) => Repositories .user(txn) .getAllNamesAndEmails()); From 885e2121b1e8ff87eac1d8002a766de57ed9e01c Mon Sep 17 00:00:00 2001 From: Nikhil Dange Date: Mon, 29 Apr 2024 19:27:50 -0700 Subject: [PATCH 17/17] linting + package.json --- package.json | 2 +- services/UserAccountService.ts | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index bb1c64096..79b112020 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@acmucsd/membership-portal", - "version": "3.6.0", + "version": "3.6.1", "description": "REST API for ACM UCSD's membership portal.", "main": "index.d.ts", "files": [ diff --git a/services/UserAccountService.ts b/services/UserAccountService.ts index 0c8df13b6..ab0dc9260 100644 --- a/services/UserAccountService.ts +++ b/services/UserAccountService.ts @@ -20,11 +20,10 @@ import { UserPatches, UserState, PrivateProfile, - NameAndEmail + NameAndEmail, } from '../types'; import { UserRepository } from '../repositories/UserRepository'; import { UserModel } from '../models/UserModel'; -import { Name } from 'aws-sdk/clients/appstream'; @Service() export default class UserAccountService {