Skip to content

Commit

Permalink
fix: campaign type and add files
Browse files Browse the repository at this point in the history
- add files to the campaign application findOne
- replace category with campaignTypeId (category is a property of the campaignType and was used incorrectly to define it)
- linting fixes
  • Loading branch information
gparlakov committed Sep 8, 2024
1 parent 66a6354 commit 77e2138
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 101 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { CampaignApplicationState, CampaignTypeCategory } from '@prisma/client'
import { CreateCampaignApplicationDto } from '../dto/create-campaign-application.dto'
import { CampaignApplicationState } from '@prisma/client'

export const mockNewCampaignApplication = {
campaignName: 'Test Campaign',
Expand All @@ -15,7 +14,7 @@ export const mockNewCampaignApplication = {
campaignGuarantee: 'Test guarantee',
otherFinanceSources: 'Test otherFinanceSources',
otherNotes: 'Test otherNotes',
category: CampaignTypeCategory.medical,
campaignTypeId: 'ffdbcc41-85ec-0000-9e59-0662f3b433af',
}

export const mockSingleCampaignApplication = {
Expand All @@ -37,7 +36,7 @@ export const mockSingleCampaignApplication = {
otherFinanceSources: 'test otherFinanceSources1',
otherNotes: 'test otherNotes1',
state: CampaignApplicationState.review,
category: CampaignTypeCategory.medical,
campaignTypeId: 'ffdbcc41-85ec-0000-9e59-0662f3b433af',
ticketURL: 'testsodifhso1',
archived: false,
documents: [{ id: 'fileId' }],
Expand All @@ -63,7 +62,7 @@ export const mockCampaigns = [
otherFinanceSources: 'test otherFinanceSources1',
otherNotes: 'test otherNotes1',
state: CampaignApplicationState.review,
category: CampaignTypeCategory.medical,
campaignTypeId: 'ffdbcc41-85ec-0000-9e59-0662f3b433af',
ticketURL: 'testsodifhso1',
archived: false,
},
Expand All @@ -86,7 +85,7 @@ export const mockCampaigns = [
otherFinanceSources: 'test otherFinanceSources2',
otherNotes: 'test otherNotes2',
state: CampaignApplicationState.review,
category: CampaignTypeCategory.medical,
campaignTypeId: 'ffdbcc41-85ec-0000-9e59-0662f3b433af',
ticketURL: 'testsodifhso2',
archived: false,
},
Expand Down Expand Up @@ -117,42 +116,5 @@ export const mockUpdateCampaignApplication = {
campaignGuarantee: 'Test guarantee',
otherFinanceSources: 'Test otherFinanceSources',
otherNotes: 'Test otherNotes',
category: CampaignTypeCategory.medical,
}

const mockUpdateCampaignApplicationResponceOrganizer = {
amount: '1000',
beneficiary: 'Test beneficary',
campaignGuarantee: 'Test guarantee',
campaignName: 'Test Campaign',
category: 'medical',
description: 'Test description',
goal: 'Test goal',
history: 'Test history',
organizerBeneficiaryRel: 'Test organizerBeneficiaryRel',
organizerEmail: '[email protected]',
organizerName: 'Test Organizer',
organizerPhone: '123456789',
otherFinanceSources: 'Test otherFinanceSources',
otherNotes: 'Test otherNotes',
}

const mockUpdateCampaignApplicationResponceAdmin = {
amount: '1000',
beneficiary: 'Test beneficary',
campaignGuarantee: 'Test guarantee',
campaignName: 'Test Campaign',
category: 'medical',
description: 'Test description',
goal: 'Test goal',
history: 'Test history',
organizerBeneficiaryRel: 'Test organizerBeneficiaryRel',
organizerEmail: '[email protected]',
organizerName: 'Test Organizer',
organizerPhone: '123456789',
otherFinanceSources: 'Test otherFinanceSources',
otherNotes: 'Test otherNotes',
archived: false,
state: 'active',
ticketURL: 'http://test.com/ticket',
campaignTypeId: 'ffdbcc41-85ec-0000-9e59-0662f3b433af',
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
import {
Controller,
Get,
Post,
Body,
Patch,
Param,
Controller,
Delete,
ForbiddenException,
NotFoundException,
Get,
Logger,
NotFoundException,
Param,
Patch,
Post,
UploadedFiles,
UseInterceptors,
Delete,
} from '@nestjs/common'
import { CampaignApplicationService } from './campaign-application.service'
import { CreateCampaignApplicationDto } from './dto/create-campaign-application.dto'
import { UpdateCampaignApplicationDto } from './dto/update-campaign-application.dto'
import { FilesInterceptor } from '@nestjs/platform-express'
import { ApiTags } from '@nestjs/swagger'
import { AuthenticatedUser, RoleMatchingMode, Roles } from 'nest-keycloak-connect'
import { RealmViewSupporters, ViewSupporters } from '@podkrepi-bg/podkrepi-types'
import { AuthenticatedUser } from 'nest-keycloak-connect'
import { KeycloakTokenParsed, isAdmin } from '../auth/keycloak'
import { PersonService } from '../person/person.service'
import { FilesInterceptor } from '@nestjs/platform-express'
import { validateFileType } from '../common/files'
import { PersonService } from '../person/person.service'
import { CampaignApplicationService } from './campaign-application.service'
import { CreateCampaignApplicationDto } from './dto/create-campaign-application.dto'
import { UpdateCampaignApplicationDto } from './dto/update-campaign-application.dto'

@ApiTags('campaign-application')
@Controller('campaign-application')
Expand Down Expand Up @@ -85,7 +84,7 @@ export class CampaignApplicationController {
}

const isAdminFlag = isAdmin(user)

return this.campaignApplicationService.findOne(id, isAdminFlag, person)
}

Expand All @@ -98,7 +97,7 @@ export class CampaignApplicationController {
}

const isAdminFlag = isAdmin(user)

return this.campaignApplicationService.deleteFile(id, isAdminFlag, person)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
import { Test, TestingModule } from '@nestjs/testing'
import { CampaignApplicationService } from './campaign-application.service'
import { CreateCampaignApplicationDto } from './dto/create-campaign-application.dto'
import { BadRequestException, ForbiddenException, NotFoundException } from '@nestjs/common'
import { CampaignApplicationFileRole, CampaignTypeCategory, Person } from '@prisma/client'
import { prismaMock, MockPrismaService } from '../prisma/prisma-client.mock'
import { Test, TestingModule } from '@nestjs/testing'
import { OrganizerService } from '../organizer/organizer.service'
import { personMock } from '../person/__mock__/personMock'
import { MockPrismaService, prismaMock } from '../prisma/prisma-client.mock'
import { S3Service } from '../s3/s3.service'
import {
mockCampaigns,
mockCreatedCampaignApplication,
mockNewCampaignApplication,
mockSingleCampaignApplication,
mockUpdateCampaignApplication,
} from './__mocks__/campaign-application-mocks'
import { S3Service } from '../s3/s3.service'
import {
mockCampaignApplicationFileFn,
mockCampaignApplicationFilesFn,
mockCampaignApplicationUploadFileFn,
} from './__mocks__/campaing-application-file-mocks'
import { CampaignApplicationService } from './campaign-application.service'
import { CreateCampaignApplicationDto } from './dto/create-campaign-application.dto'

describe('CampaignApplicationService', () => {
let service: CampaignApplicationService
Expand Down Expand Up @@ -143,7 +141,7 @@ describe('CampaignApplicationService', () => {
campaignGuarantee: 'Test guarantee',
otherFinanceSources: 'Test otherFinanceSources',
otherNotes: 'Test otherNotes',
category: CampaignTypeCategory.medical,
campaignTypeId: 'ffdbcc41-85ec-0000-9e59-0662f3b433af',
organizerId: mockOrganizerId,
},
})
Expand Down
30 changes: 21 additions & 9 deletions apps/api/src/campaign-application/campaign-application.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ export class CampaignApplicationService {
private s3: S3Service,
) {}

async getCampaignByIdWithPersonIds(id: string): Promise<UpdateCampaignApplicationDto> {
throw new Error('Method not implemented.')
}

async create(createCampaignApplicationDto: CreateCampaignApplicationDto, person: Person) {
try {
if (
Expand Down Expand Up @@ -59,7 +55,7 @@ export class CampaignApplicationService {
campaignGuarantee: createCampaignApplicationDto.campaignGuarantee,
otherFinanceSources: createCampaignApplicationDto.otherFinanceSources,
otherNotes: createCampaignApplicationDto.otherNotes,
category: createCampaignApplicationDto.category,
campaignTypeId: createCampaignApplicationDto.campaignTypeId,
organizerId: organizer.id,
}

Expand Down Expand Up @@ -96,10 +92,22 @@ export class CampaignApplicationService {
}
}

async findOne(id: string, isAdminFlag: boolean, person: Prisma.PersonGetPayload<{ include: { organizer: {select:{id:true}}}}>) {
async findOne(
id: string,
isAdminFlag: boolean,
person: Prisma.PersonGetPayload<{ include: { organizer: { select: { id: true } } } }>,
) {
try {
const singleCampaignApplication = await this.prisma.campaignApplication.findUnique({
where: { id },
include: {
documents: {
select: {
id: true,
filename: true,
},
},
},
})
if (!singleCampaignApplication) {
throw new NotFoundException('Campaign application doesnt exist')
Expand All @@ -116,7 +124,11 @@ export class CampaignApplicationService {
}
}

async deleteFile(id: string, isAdminFlag: boolean, person: Prisma.PersonGetPayload<{ include: { organizer: {select:{id:true}}}}>) {
async deleteFile(
id: string,
isAdminFlag: boolean,
person: Prisma.PersonGetPayload<{ include: { organizer: { select: { id: true } } } }>,
) {
try {
const campaignApplication = await this.prisma.campaignApplication.findFirst({
where: {
Expand Down Expand Up @@ -184,7 +196,7 @@ export class CampaignApplicationService {
campaignGuarantee: updateCampaignApplicationDto?.campaignGuarantee,
otherFinanceSources: updateCampaignApplicationDto?.otherFinanceSources,
otherNotes: updateCampaignApplicationDto?.otherNotes,
category: updateCampaignApplicationDto?.category,
campaignTypeId: updateCampaignApplicationDto?.campaignTypeId,
},
})

Expand All @@ -208,7 +220,7 @@ export class CampaignApplicationService {
campaignGuarantee: updateCampaignApplicationDto?.campaignGuarantee,
otherFinanceSources: updateCampaignApplicationDto?.otherFinanceSources,
otherNotes: updateCampaignApplicationDto?.otherNotes,
category: updateCampaignApplicationDto?.category,
campaignTypeId: updateCampaignApplicationDto?.campaignTypeId,
state: updateCampaignApplicationDto?.state,
ticketURL: updateCampaignApplicationDto?.ticketURL,
archived: updateCampaignApplicationDto?.archived,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiProperty } from '@nestjs/swagger'
import { CampaignTypeCategory, Prisma } from '@prisma/client'
import { Prisma } from '@prisma/client'
import { Expose } from 'class-transformer'
import { IsBoolean, IsNotEmpty, IsOptional, IsString } from 'class-validator'

Expand Down Expand Up @@ -116,10 +116,11 @@ export class CreateCampaignApplicationDto {
@IsOptional()
otherNotes?: string

@ApiProperty({ enum: CampaignTypeCategory })
@ApiProperty()
@Expose()
@IsString()
@IsOptional()
category?: CampaignTypeCategory
campaignTypeId?: string

public toEntity(): Prisma.CampaignApplicationCreateInput {
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { CampaignTypeCategory } from '@prisma/client'
import { ApiProperty } from '@nestjs/swagger'

export class CreateCampaignApplicationDto {
organizerName: string
organizerEmail?: string
Expand All @@ -15,8 +12,7 @@ export class CreateCampaignApplicationDto {
campaignGuarantee?: string
otherFinanceSources?: string
otherNotes?: string
@ApiProperty({ enum: CampaignTypeCategory })
category?: CampaignTypeCategory
campaignTypeId?: string
ticketURL?: string
archived?: boolean
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import { CampaignTypeCategory } from '@prisma/client'
import { ApiProperty } from '@nestjs/swagger'

export class UpdateCampaignApplicationDto {
organizerName?: string
organizerEmail?: string
Expand All @@ -15,8 +12,7 @@ export class UpdateCampaignApplicationDto {
campaignGuarantee?: string
otherFinanceSources?: string
otherNotes?: string
@ApiProperty({ enum: CampaignTypeCategory })
category?: CampaignTypeCategory
campaignTypeId?: string
ticketURL?: string
archived?: boolean
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { CampaignApplicationState, CampaignTypeCategory } from '@prisma/client'
import { CampaignApplicationState } from '@prisma/client'
import { Organizer } from '../../organizer/entities/organizer.entity'
import { CampaignApplicationFile } from '../../campaignApplicationFile/entities/campaignApplicationFile.entity'

Expand All @@ -23,7 +23,7 @@ export class CampaignApplication {
otherFinanceSources: string | null
otherNotes: string | null
state: CampaignApplicationState
category: CampaignTypeCategory | null
campaignTypeId: string | null
ticketURL: string | null
archived: boolean | null
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
Warnings:
- You are about to drop the column `category` on the `campaign_applications` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "campaign_applications" DROP COLUMN "category",
ADD COLUMN "campaignTypeId" UUID;
6 changes: 4 additions & 2 deletions podkrepi.dbml
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ Table campaign_applications {
otherFinanceSources String
otherNotes String
state CampaignApplicationState [not null, default: 'review']
category CampaignTypeCategory [default: 'others']
campaignTypeId String
ticketURL String
archived Boolean [default: false]

Expand Down Expand Up @@ -988,4 +988,6 @@ Ref: expense_files.uploaderId > people.id

Ref: documents.ownerId > people.id

Ref: campaign_applications.organizerId > organizers.id
Ref: campaign_applications.organizerId > organizers.id

Ref: campaign_application_files.campaignApplicationId > campaign_applications.id
14 changes: 7 additions & 7 deletions schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -1008,9 +1008,9 @@ enum EmailType {

/// CampaignApplication represents a request for a new campaign - it is not a Campaign yet and has to proove it needs to be
model CampaignApplication {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
createdAt DateTime @default(now()) @map("created_at") @db.Timestamptz(6)
updatedAt DateTime? @updatedAt @map("updated_at") @db.Timestamptz(6)
// organizer editable fields
// need to be logged in to create a campaign application
Expand All @@ -1033,10 +1033,10 @@ model CampaignApplication {
otherNotes String? @db.Text
// operator editable fields
state CampaignApplicationState @default(review)
category CampaignTypeCategory? @default(others)
ticketURL String? @db.VarChar(500)
archived Boolean? @default(false)
state CampaignApplicationState @default(review)
campaignTypeId String? @db.Uuid
ticketURL String? @db.VarChar(500)
archived Boolean? @default(false)
@@map("campaign_applications")
}
Expand Down

0 comments on commit 77e2138

Please sign in to comment.