Skip to content

Commit

Permalink
fix: add campaign end
Browse files Browse the repository at this point in the history
- add campaign end type and date
  • Loading branch information
gparlakov committed Sep 11, 2024
1 parent 3a6b125 commit 733f741
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -40,6 +42,8 @@ export const mockSingleCampaignApplication = {
ticketURL: 'testsodifhso1',
archived: false,
documents: [{ id: 'fileId' }],
campaignEnd: 'funds',
campaignEndDate: undefined,
}

export const mockCampaigns = [
Expand Down Expand Up @@ -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',
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ describe('CampaignApplicationService', () => {
transparencyTermsAccepted: true,
personalInformationProcessingAccepted: true,
toEntity: new CreateCampaignApplicationDto().toEntity,
campaignEndDate: '2024-01-01'
}

const mockOrganizerId = 'mockOrganizerId'
Expand Down Expand Up @@ -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'),
},
})

Expand Down Expand Up @@ -281,6 +284,7 @@ describe('CampaignApplicationService', () => {
where: { id: '1' },
data: {
...mockUpdateCampaignApplication,
campaignEndDate: new Date('2024-09-09T00:00:00.000Z')
},
})
})
Expand Down Expand Up @@ -336,6 +340,7 @@ describe('CampaignApplicationService', () => {
where: { id: '1' },
data: {
...mockUpdateCampaignApplication,
campaignEndDate: new Date('2024-09-09T00:00:00.000Z')
},
})
})
Expand Down
15 changes: 15 additions & 0 deletions apps/api/src/campaign-application/campaign-application.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -197,6 +208,8 @@ export class CampaignApplicationService {
otherFinanceSources: updateCampaignApplicationDto?.otherFinanceSources,
otherNotes: updateCampaignApplicationDto?.otherNotes,
campaignTypeId: updateCampaignApplicationDto?.campaignTypeId,
campaignEnd: updateCampaignApplicationDto.campaignEnd,
campaignEndDate: dateMaybe(updateCampaignApplicationDto.campaignEndDate),
},
})

Expand Down Expand Up @@ -224,6 +237,8 @@ export class CampaignApplicationService {
state: updateCampaignApplicationDto?.state,
ticketURL: updateCampaignApplicationDto?.ticketURL,
archived: updateCampaignApplicationDto?.archived,
campaignEnd: updateCampaignApplicationDto.campaignEnd,
campaignEndDate: dateMaybe(updateCampaignApplicationDto.campaignEndDate),
},
})
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ export class CreateCampaignApplicationDto {
campaignTypeId?: string
ticketURL?: string
archived?: boolean
campaignEnd?: string
campaignEndDate?: Date
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ export class UpdateCampaignApplicationDto {
campaignTypeId?: string
ticketURL?: string
archived?: boolean
campaignEnd?: string
campaignEndDate?: Date
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ export class CampaignApplication {
campaignTypeId: string | null
ticketURL: string | null
archived: boolean | null
campaignEnd: string | null
campaignEndDate: Date | null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "campaign_applications" ADD COLUMN "campaignEnd" TEXT DEFAULT 'funds',
ADD COLUMN "campaignEndDate" TIMESTAMPTZ(6);
2 changes: 2 additions & 0 deletions podkrepi.dbml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Expand Down
2 changes: 2 additions & 0 deletions schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down

0 comments on commit 733f741

Please sign in to comment.