From dce387e3ff041fdfacb839f0f51cc6af2eb94478 Mon Sep 17 00:00:00 2001 From: = Date: Mon, 21 Oct 2024 19:10:21 -0700 Subject: [PATCH 1/5] added food field to events table --- api/validators/EventControllerRequests.ts | 3 +++ migrations/0046-add-food-column.ts | 25 +++++++++++++++++++++++ models/EventModel.ts | 4 ++++ tests/Seeds.ts | 1 + tests/data/EventFactory.ts | 1 + tests/event.test.ts | 4 ++++ tests/merchOrder.test.ts | 3 +++ types/ApiRequests.ts | 1 + types/ApiResponses.ts | 1 + 9 files changed, 43 insertions(+) create mode 100644 migrations/0046-add-food-column.ts diff --git a/api/validators/EventControllerRequests.ts b/api/validators/EventControllerRequests.ts index 1a8a1306..fa50aab6 100644 --- a/api/validators/EventControllerRequests.ts +++ b/api/validators/EventControllerRequests.ts @@ -35,6 +35,9 @@ export class OptionalEventProperties implements IOptionalEventProperties { @Allow() googleCalendarEvent?: Uuid; + + @Allow() + food?: string; } export class Event extends OptionalEventProperties implements IEvent { diff --git a/migrations/0046-add-food-column.ts b/migrations/0046-add-food-column.ts new file mode 100644 index 00000000..d6658530 --- /dev/null +++ b/migrations/0046-add-food-column.ts @@ -0,0 +1,25 @@ +import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm'; + +const TABLE_NAME = 'Events'; + +export class AddFoodColumn1728959627663 implements MigrationInterface { + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.addColumns(TABLE_NAME, [ + new TableColumn({ + name: 'food', + type: 'varchar(255)', + isNullable: true, + }), + ]); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.dropColumns(TABLE_NAME, [ + new TableColumn({ + name: 'food', + type: 'varchar(255)', + }), + ]); + } +} diff --git a/models/EventModel.ts b/models/EventModel.ts index 256fa443..23b2a9b4 100644 --- a/models/EventModel.ts +++ b/models/EventModel.ts @@ -73,6 +73,9 @@ export class EventModel extends BaseEntity { @Column('varchar', { nullable: true }) googleCalendarEvent: Uuid; + @Column('varchar', { nullable: true }) + food: string; + public getPublicEvent(canSeeAttendanceCode = false): PublicEvent { const publicEvent: PublicEvent = { uuid: this.uuid, @@ -91,6 +94,7 @@ export class EventModel extends BaseEntity { staffPointBonus: this.staffPointBonus, discordEvent: this.discordEvent, googleCalendarEvent: this.googleCalendarEvent, + food: this.food, }; if (canSeeAttendanceCode) publicEvent.attendanceCode = this.attendanceCode; return publicEvent; diff --git a/tests/Seeds.ts b/tests/Seeds.ts index 979db0fc..2238de0f 100644 --- a/tests/Seeds.ts +++ b/tests/Seeds.ts @@ -209,6 +209,7 @@ async function seed(): Promise { ...EventFactory.daysBefore(6), attendanceCode: 'galaxybrain', ...staffed, + food: 'Boba', }); const PAST_HACK_WORKSHOP = EventFactory.fake({ title: 'Hack: Intro to Rust', diff --git a/tests/data/EventFactory.ts b/tests/data/EventFactory.ts index bf6a9d38..b9dd8f7c 100644 --- a/tests/data/EventFactory.ts +++ b/tests/data/EventFactory.ts @@ -43,6 +43,7 @@ export class EventFactory { thumbnail: FactoryUtils.getRandomImageUrl(), discordEvent: faker.datatype.hexaDecimal(10), googleCalendarEvent: faker.datatype.hexaDecimal(10), + food: null, }); return EventModel.merge(fake, substitute); } diff --git a/tests/event.test.ts b/tests/event.test.ts index ef1d64dd..111e427b 100644 --- a/tests/event.test.ts +++ b/tests/event.test.ts @@ -39,6 +39,7 @@ describe('event creation', () => { start: moment().subtract(2, 'hour').toDate(), end: moment().subtract(1, 'hour').toDate(), attendanceCode: 'p4rty', + food: 'Boba', pointValue: 10, }; @@ -57,6 +58,7 @@ describe('event creation', () => { expect(eventResponse.event.committee).toEqual(event.committee); expect(eventResponse.event.start).toEqual(event.start); expect(eventResponse.event.end).toEqual(event.end); + expect(eventResponse.event.food).toEqual(event.food); expect(eventResponse.event.pointValue).toEqual(event.pointValue); // verifying response from event lookup @@ -83,6 +85,7 @@ describe('event creation', () => { start: moment().subtract(2, 'hour').toDate(), end: moment().subtract(1, 'hour').toDate(), attendanceCode: 'p4rty', + food: '', pointValue: 10, }; @@ -114,6 +117,7 @@ describe('event creation', () => { start: moment().subtract(1, 'hour').toDate(), end: moment().subtract(2, 'hour').toDate(), attendanceCode: 'p4rty', + food: null, pointValue: 10, }; diff --git a/tests/merchOrder.test.ts b/tests/merchOrder.test.ts index d3ab8720..36f068e2 100644 --- a/tests/merchOrder.test.ts +++ b/tests/merchOrder.test.ts @@ -994,6 +994,9 @@ describe('merch order pickup events', () => { const persistedPickupEvent = await conn.manager.findOne(OrderPickupEventModel, { relations: ['orders', 'linkedEvent'] }); + + console.log(persistedPickupEvent); + console.log(pickupEvent); expect(persistedPickupEvent).toStrictEqual(pickupEvent); // edit a linked event diff --git a/types/ApiRequests.ts b/types/ApiRequests.ts index 816b59f7..297f609a 100644 --- a/types/ApiRequests.ts +++ b/types/ApiRequests.ts @@ -157,6 +157,7 @@ export interface OptionalEventProperties { staffPointBonus?: number; discordEvent?: Uuid; googleCalendarEvent?: Uuid; + food?: string; } export interface Event extends OptionalEventProperties { diff --git a/types/ApiResponses.ts b/types/ApiResponses.ts index d3dfa353..f7d3eef6 100644 --- a/types/ApiResponses.ts +++ b/types/ApiResponses.ts @@ -118,6 +118,7 @@ export interface PublicEvent { staffPointBonus: number; discordEvent: Uuid; googleCalendarEvent: Uuid; + food: string; } export interface GetPastEventsResponse extends ApiResponse { From 771e49d45962cc31ef48ee9658ea86420067bbd5 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 22 Oct 2024 11:34:45 -0700 Subject: [PATCH 2/5] fixed lint errors --- migrations/0046-add-food-column.ts | 1 - tests/merchOrder.test.ts | 2 -- 2 files changed, 3 deletions(-) diff --git a/migrations/0046-add-food-column.ts b/migrations/0046-add-food-column.ts index d6658530..040b44ac 100644 --- a/migrations/0046-add-food-column.ts +++ b/migrations/0046-add-food-column.ts @@ -3,7 +3,6 @@ import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm'; const TABLE_NAME = 'Events'; export class AddFoodColumn1728959627663 implements MigrationInterface { - public async up(queryRunner: QueryRunner): Promise { await queryRunner.addColumns(TABLE_NAME, [ new TableColumn({ diff --git a/tests/merchOrder.test.ts b/tests/merchOrder.test.ts index 36f068e2..89ce53a3 100644 --- a/tests/merchOrder.test.ts +++ b/tests/merchOrder.test.ts @@ -995,8 +995,6 @@ describe('merch order pickup events', () => { const persistedPickupEvent = await conn.manager.findOne(OrderPickupEventModel, { relations: ['orders', 'linkedEvent'] }); - console.log(persistedPickupEvent); - console.log(pickupEvent); expect(persistedPickupEvent).toStrictEqual(pickupEvent); // edit a linked event From 8ab35b4589786111b157449b7c7b13a5592bd7d4 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 22 Oct 2024 11:35:44 -0700 Subject: [PATCH 3/5] updated api version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a3480e32..3ecfdac4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@acmucsd/membership-portal", - "version": "3.6.2", + "version": "3.6.3", "description": "REST API for ACM UCSD's membership portal.", "main": "index.d.ts", "files": [ From 772294838bf21f19263c9a373c8da55e7ab137d7 Mon Sep 17 00:00:00 2001 From: = Date: Tue, 22 Oct 2024 17:59:50 -0700 Subject: [PATCH 4/5] fixed version, changed food to foodItems --- api/validators/EventControllerRequests.ts | 2 +- ...ood-column.ts => 0046-add-food-items-column.ts} | 14 +++++++------- models/EventModel.ts | 4 ++-- package.json | 2 +- tests/Seeds.ts | 2 +- tests/data/EventFactory.ts | 2 +- tests/event.test.ts | 8 ++++---- types/ApiRequests.ts | 2 +- types/ApiResponses.ts | 2 +- 9 files changed, 19 insertions(+), 19 deletions(-) rename migrations/{0046-add-food-column.ts => 0046-add-food-items-column.ts} (62%) diff --git a/api/validators/EventControllerRequests.ts b/api/validators/EventControllerRequests.ts index fa50aab6..11686fb5 100644 --- a/api/validators/EventControllerRequests.ts +++ b/api/validators/EventControllerRequests.ts @@ -37,7 +37,7 @@ export class OptionalEventProperties implements IOptionalEventProperties { googleCalendarEvent?: Uuid; @Allow() - food?: string; + foodItems?: string; } export class Event extends OptionalEventProperties implements IEvent { diff --git a/migrations/0046-add-food-column.ts b/migrations/0046-add-food-items-column.ts similarity index 62% rename from migrations/0046-add-food-column.ts rename to migrations/0046-add-food-items-column.ts index 040b44ac..65e1123d 100644 --- a/migrations/0046-add-food-column.ts +++ b/migrations/0046-add-food-items-column.ts @@ -2,23 +2,23 @@ import { MigrationInterface, QueryRunner, TableColumn } from 'typeorm'; const TABLE_NAME = 'Events'; -export class AddFoodColumn1728959627663 implements MigrationInterface { +export class AddFoodItemsColumn1728959627663 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { - await queryRunner.addColumns(TABLE_NAME, [ + await queryRunner.addColumn(TABLE_NAME, new TableColumn({ - name: 'food', + name: 'foodItems', type: 'varchar(255)', isNullable: true, }), - ]); + ); } public async down(queryRunner: QueryRunner): Promise { - await queryRunner.dropColumns(TABLE_NAME, [ + await queryRunner.dropColumn(TABLE_NAME, new TableColumn({ - name: 'food', + name: 'foodItems', type: 'varchar(255)', }), - ]); + ); } } diff --git a/models/EventModel.ts b/models/EventModel.ts index 23b2a9b4..ac58c94d 100644 --- a/models/EventModel.ts +++ b/models/EventModel.ts @@ -74,7 +74,7 @@ export class EventModel extends BaseEntity { googleCalendarEvent: Uuid; @Column('varchar', { nullable: true }) - food: string; + foodItems: string; public getPublicEvent(canSeeAttendanceCode = false): PublicEvent { const publicEvent: PublicEvent = { @@ -94,7 +94,7 @@ export class EventModel extends BaseEntity { staffPointBonus: this.staffPointBonus, discordEvent: this.discordEvent, googleCalendarEvent: this.googleCalendarEvent, - food: this.food, + foodItems: this.foodItems, }; if (canSeeAttendanceCode) publicEvent.attendanceCode = this.attendanceCode; return publicEvent; diff --git a/package.json b/package.json index 3ecfdac4..04363810 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@acmucsd/membership-portal", - "version": "3.6.3", + "version": "3.7.0", "description": "REST API for ACM UCSD's membership portal.", "main": "index.d.ts", "files": [ diff --git a/tests/Seeds.ts b/tests/Seeds.ts index 2238de0f..2530a95c 100644 --- a/tests/Seeds.ts +++ b/tests/Seeds.ts @@ -209,7 +209,7 @@ async function seed(): Promise { ...EventFactory.daysBefore(6), attendanceCode: 'galaxybrain', ...staffed, - food: 'Boba', + foodItems: 'Boba', }); const PAST_HACK_WORKSHOP = EventFactory.fake({ title: 'Hack: Intro to Rust', diff --git a/tests/data/EventFactory.ts b/tests/data/EventFactory.ts index b9dd8f7c..ff8338e5 100644 --- a/tests/data/EventFactory.ts +++ b/tests/data/EventFactory.ts @@ -43,7 +43,7 @@ export class EventFactory { thumbnail: FactoryUtils.getRandomImageUrl(), discordEvent: faker.datatype.hexaDecimal(10), googleCalendarEvent: faker.datatype.hexaDecimal(10), - food: null, + foodItems: null, }); return EventModel.merge(fake, substitute); } diff --git a/tests/event.test.ts b/tests/event.test.ts index 111e427b..9161a4c6 100644 --- a/tests/event.test.ts +++ b/tests/event.test.ts @@ -39,7 +39,7 @@ describe('event creation', () => { start: moment().subtract(2, 'hour').toDate(), end: moment().subtract(1, 'hour').toDate(), attendanceCode: 'p4rty', - food: 'Boba', + foodItems: 'Boba', pointValue: 10, }; @@ -58,7 +58,7 @@ describe('event creation', () => { expect(eventResponse.event.committee).toEqual(event.committee); expect(eventResponse.event.start).toEqual(event.start); expect(eventResponse.event.end).toEqual(event.end); - expect(eventResponse.event.food).toEqual(event.food); + expect(eventResponse.event.foodItems).toEqual(event.foodItems); expect(eventResponse.event.pointValue).toEqual(event.pointValue); // verifying response from event lookup @@ -85,7 +85,7 @@ describe('event creation', () => { start: moment().subtract(2, 'hour').toDate(), end: moment().subtract(1, 'hour').toDate(), attendanceCode: 'p4rty', - food: '', + foodItems: '', pointValue: 10, }; @@ -117,7 +117,7 @@ describe('event creation', () => { start: moment().subtract(1, 'hour').toDate(), end: moment().subtract(2, 'hour').toDate(), attendanceCode: 'p4rty', - food: null, + foodItems: null, pointValue: 10, }; diff --git a/types/ApiRequests.ts b/types/ApiRequests.ts index 297f609a..ed571143 100644 --- a/types/ApiRequests.ts +++ b/types/ApiRequests.ts @@ -157,7 +157,7 @@ export interface OptionalEventProperties { staffPointBonus?: number; discordEvent?: Uuid; googleCalendarEvent?: Uuid; - food?: string; + foodItems?: string; } export interface Event extends OptionalEventProperties { diff --git a/types/ApiResponses.ts b/types/ApiResponses.ts index f7d3eef6..275d6e77 100644 --- a/types/ApiResponses.ts +++ b/types/ApiResponses.ts @@ -118,7 +118,7 @@ export interface PublicEvent { staffPointBonus: number; discordEvent: Uuid; googleCalendarEvent: Uuid; - food: string; + foodItems: string; } export interface GetPastEventsResponse extends ApiResponse { From 21f55ec38b53000e0ccde129897597fcd6b82c2d Mon Sep 17 00:00:00 2001 From: = Date: Tue, 22 Oct 2024 18:02:15 -0700 Subject: [PATCH 5/5] fix lint error --- migrations/0046-add-food-items-column.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/migrations/0046-add-food-items-column.ts b/migrations/0046-add-food-items-column.ts index 65e1123d..a7f4f142 100644 --- a/migrations/0046-add-food-items-column.ts +++ b/migrations/0046-add-food-items-column.ts @@ -9,8 +9,7 @@ export class AddFoodItemsColumn1728959627663 implements MigrationInterface { name: 'foodItems', type: 'varchar(255)', isNullable: true, - }), - ); + })); } public async down(queryRunner: QueryRunner): Promise { @@ -18,7 +17,6 @@ export class AddFoodItemsColumn1728959627663 implements MigrationInterface { new TableColumn({ name: 'foodItems', type: 'varchar(255)', - }), - ); + })); } }