From 2698a7b1de7d68c9e792b4e39e551abefe524cf7 Mon Sep 17 00:00:00 2001 From: Georgi Parlakov Date: Mon, 9 Sep 2024 12:47:02 +0300 Subject: [PATCH] fix: add campaign end - add campaign end type and date --- .../__mocks__/campaign-application-mocks.ts | 6 ++++++ .../campaign-application.service.spec.ts | 5 +++++ .../campaign-application.service.ts | 15 +++++++++++++++ .../dto/create-campaign-application.dto.ts | 14 +++++++++++++- .../dto/create-campaignApplication.dto.ts | 2 ++ .../dto/update-campaignApplication.dto.ts | 2 ++ .../entities/campaignApplication.entity.ts | 2 ++ .../migration.sql | 3 +++ podkrepi.dbml | 2 ++ schema.prisma | 2 ++ 10 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 migrations/20240909080426_campaign_application_add_campaign_end/migration.sql diff --git a/apps/api/src/campaign-application/__mocks__/campaign-application-mocks.ts b/apps/api/src/campaign-application/__mocks__/campaign-application-mocks.ts index 49dfea32..d5a6387e 100644 --- a/apps/api/src/campaign-application/__mocks__/campaign-application-mocks.ts +++ b/apps/api/src/campaign-application/__mocks__/campaign-application-mocks.ts @@ -15,6 +15,8 @@ export const mockNewCampaignApplication = { otherFinanceSources: 'Test otherFinanceSources', otherNotes: 'Test otherNotes', campaignTypeId: 'ffdbcc41-85ec-0000-9e59-0662f3b433af', + campaignEnd: 'funds', + campaignEndDate: '2024-02-02', } export const mockSingleCampaignApplication = { @@ -40,6 +42,8 @@ export const mockSingleCampaignApplication = { ticketURL: 'testsodifhso1', archived: false, documents: [{ id: 'fileId' }], + campaignEnd: 'funds', + campaignEndDate: undefined, } export const mockCampaigns = [ @@ -117,4 +121,6 @@ export const mockUpdateCampaignApplication = { otherFinanceSources: 'Test otherFinanceSources', otherNotes: 'Test otherNotes', campaignTypeId: 'ffdbcc41-85ec-0000-9e59-0662f3b433af', + campaignEnd: 'funds', + campaignEndDate: '2024-09-09', } diff --git a/apps/api/src/campaign-application/campaign-application.service.spec.ts b/apps/api/src/campaign-application/campaign-application.service.spec.ts index acca17a3..d9c35fd8 100644 --- a/apps/api/src/campaign-application/campaign-application.service.spec.ts +++ b/apps/api/src/campaign-application/campaign-application.service.spec.ts @@ -106,6 +106,7 @@ describe('CampaignApplicationService', () => { transparencyTermsAccepted: true, personalInformationProcessingAccepted: true, toEntity: new CreateCampaignApplicationDto().toEntity, + campaignEndDate: '2024-01-01' } const mockOrganizerId = 'mockOrganizerId' @@ -143,6 +144,8 @@ describe('CampaignApplicationService', () => { otherNotes: 'Test otherNotes', campaignTypeId: 'ffdbcc41-85ec-0000-9e59-0662f3b433af', organizerId: mockOrganizerId, + campaignEnd: 'funds', + campaignEndDate: new Date('2024-01-01T00:00:00.000Z'), }, }) @@ -281,6 +284,7 @@ describe('CampaignApplicationService', () => { where: { id: '1' }, data: { ...mockUpdateCampaignApplication, + campaignEndDate: new Date('2024-09-09T00:00:00.000Z') }, }) }) @@ -336,6 +340,7 @@ describe('CampaignApplicationService', () => { where: { id: '1' }, data: { ...mockUpdateCampaignApplication, + campaignEndDate: new Date('2024-09-09T00:00:00.000Z') }, }) }) diff --git a/apps/api/src/campaign-application/campaign-application.service.ts b/apps/api/src/campaign-application/campaign-application.service.ts index 062285d2..d8b29d81 100644 --- a/apps/api/src/campaign-application/campaign-application.service.ts +++ b/apps/api/src/campaign-application/campaign-application.service.ts @@ -12,6 +12,15 @@ import { OrganizerService } from '../organizer/organizer.service' import { CampaignApplicationFileRole, Person, Prisma } from '@prisma/client' import { S3Service } from './../s3/s3.service' import { CreateCampaignApplicationFileDto } from './dto/create-campaignApplication-file.dto' + +function dateMaybe (d?: string) { + return d != null && + typeof d === 'string' && + new Date(d).toString() != new Date('----invalid date ---').toString() + ? new Date(d) + : undefined +} + @Injectable() export class CampaignApplicationService { private readonly bucketName: string = 'campaignapplication-files' @@ -57,6 +66,8 @@ export class CampaignApplicationService { otherNotes: createCampaignApplicationDto.otherNotes, campaignTypeId: createCampaignApplicationDto.campaignTypeId, organizerId: organizer.id, + campaignEnd: createCampaignApplicationDto.campaignEnd, + campaignEndDate: dateMaybe(createCampaignApplicationDto.campaignEndDate) } const newCampaignApplication = await this.prisma.campaignApplication.create({ @@ -197,6 +208,8 @@ export class CampaignApplicationService { otherFinanceSources: updateCampaignApplicationDto?.otherFinanceSources, otherNotes: updateCampaignApplicationDto?.otherNotes, campaignTypeId: updateCampaignApplicationDto?.campaignTypeId, + campaignEnd: updateCampaignApplicationDto.campaignEnd, + campaignEndDate: dateMaybe(updateCampaignApplicationDto.campaignEndDate), }, }) @@ -224,6 +237,8 @@ export class CampaignApplicationService { state: updateCampaignApplicationDto?.state, ticketURL: updateCampaignApplicationDto?.ticketURL, archived: updateCampaignApplicationDto?.archived, + campaignEnd: updateCampaignApplicationDto.campaignEnd, + campaignEndDate: dateMaybe(updateCampaignApplicationDto.campaignEndDate), }, }) } diff --git a/apps/api/src/campaign-application/dto/create-campaign-application.dto.ts b/apps/api/src/campaign-application/dto/create-campaign-application.dto.ts index 54d29061..4274ed88 100644 --- a/apps/api/src/campaign-application/dto/create-campaign-application.dto.ts +++ b/apps/api/src/campaign-application/dto/create-campaign-application.dto.ts @@ -1,7 +1,7 @@ import { ApiProperty } from '@nestjs/swagger' import { Prisma } from '@prisma/client' import { Expose } from 'class-transformer' -import { IsBoolean, IsNotEmpty, IsOptional, IsString } from 'class-validator' +import { IsBoolean, IsDateString, IsNotEmpty, IsOptional, IsString } from 'class-validator' @Expose() export class CreateCampaignApplicationDto { @@ -122,6 +122,18 @@ export class CreateCampaignApplicationDto { @IsOptional() campaignTypeId?: string + @ApiProperty() + @Expose() + @IsString() + @IsOptional() + campaignEnd?: string + + @ApiProperty() + @Expose() + @IsDateString() + @IsOptional() + campaignEndDate?: string + public toEntity(): Prisma.CampaignApplicationCreateInput { return { ...this, diff --git a/apps/api/src/domain/generated/campaignApplication/dto/create-campaignApplication.dto.ts b/apps/api/src/domain/generated/campaignApplication/dto/create-campaignApplication.dto.ts index 49485f25..af2cf96f 100644 --- a/apps/api/src/domain/generated/campaignApplication/dto/create-campaignApplication.dto.ts +++ b/apps/api/src/domain/generated/campaignApplication/dto/create-campaignApplication.dto.ts @@ -15,4 +15,6 @@ export class CreateCampaignApplicationDto { campaignTypeId?: string ticketURL?: string archived?: boolean + campaignEnd?: string + campaignEndDate?: Date } diff --git a/apps/api/src/domain/generated/campaignApplication/dto/update-campaignApplication.dto.ts b/apps/api/src/domain/generated/campaignApplication/dto/update-campaignApplication.dto.ts index f679296d..d80cacae 100644 --- a/apps/api/src/domain/generated/campaignApplication/dto/update-campaignApplication.dto.ts +++ b/apps/api/src/domain/generated/campaignApplication/dto/update-campaignApplication.dto.ts @@ -15,4 +15,6 @@ export class UpdateCampaignApplicationDto { campaignTypeId?: string ticketURL?: string archived?: boolean + campaignEnd?: string + campaignEndDate?: Date } diff --git a/apps/api/src/domain/generated/campaignApplication/entities/campaignApplication.entity.ts b/apps/api/src/domain/generated/campaignApplication/entities/campaignApplication.entity.ts index 3064a61d..b1ee5f98 100644 --- a/apps/api/src/domain/generated/campaignApplication/entities/campaignApplication.entity.ts +++ b/apps/api/src/domain/generated/campaignApplication/entities/campaignApplication.entity.ts @@ -26,4 +26,6 @@ export class CampaignApplication { campaignTypeId: string | null ticketURL: string | null archived: boolean | null + campaignEnd: string | null + campaignEndDate: Date | null } diff --git a/migrations/20240909080426_campaign_application_add_campaign_end/migration.sql b/migrations/20240909080426_campaign_application_add_campaign_end/migration.sql new file mode 100644 index 00000000..a513960c --- /dev/null +++ b/migrations/20240909080426_campaign_application_add_campaign_end/migration.sql @@ -0,0 +1,3 @@ +-- AlterTable +ALTER TABLE "campaign_applications" ADD COLUMN "campaignEnd" TEXT DEFAULT 'funds', +ADD COLUMN "campaignEndDate" TIMESTAMPTZ(6); diff --git a/podkrepi.dbml b/podkrepi.dbml index ea676f2c..316d0752 100644 --- a/podkrepi.dbml +++ b/podkrepi.dbml @@ -600,6 +600,8 @@ Table campaign_applications { campaignTypeId String ticketURL String archived Boolean [default: false] + campaignEnd String [default: 'funds'] + campaignEndDate DateTime Note: 'CampaignApplication represents a request for a new campaign - it is not a Campaign yet and has to proove it needs to be' } diff --git a/schema.prisma b/schema.prisma index 5d5b75f5..70d0c593 100644 --- a/schema.prisma +++ b/schema.prisma @@ -1037,6 +1037,8 @@ model CampaignApplication { campaignTypeId String? @db.Uuid ticketURL String? @db.VarChar(500) archived Boolean? @default(false) + campaignEnd String? @default("funds") + campaignEndDate DateTime? @db.Timestamptz(6) @@map("campaign_applications") }