diff --git a/apps/api/src/campaign/campaign.service.ts b/apps/api/src/campaign/campaign.service.ts index 917dfe7e..7f589634 100644 --- a/apps/api/src/campaign/campaign.service.ts +++ b/apps/api/src/campaign/campaign.service.ts @@ -67,7 +67,7 @@ export class CampaignService { orderBy: { endDate: 'asc', }, - where: { state: { in: [CampaignState.active, CampaignState.complete] } }, + where: { NOT: { state: { in: [CampaignState.draft, CampaignState.deleted] } } }, ...CampaignListItemSelect, }) const campaignSums = await this.getCampaignSums() @@ -81,7 +81,7 @@ export class CampaignService { async listAllCampaigns(): Promise { const campaigns = await this.prisma.campaign.findMany({ - where: { NOT: { state: { in: [CampaignState.deleted] } } }, + where: { NOT: { state: { in: [CampaignState.draft] } } }, orderBy: { updatedAt: 'desc', }, @@ -611,7 +611,7 @@ export class CampaignService { } async canAcceptDonations(campaign: Campaign): Promise { - const validStates: CampaignState[] = [CampaignState.active, CampaignState.approved] + const validStates: CampaignState[] = [CampaignState.active] if (campaign.allowDonationOnComplete) { validStates.push(CampaignState.complete) } diff --git a/migrations/20240903070800_add_new_campaign_states/migration.sql b/migrations/20240903070800_add_new_campaign_states/migration.sql new file mode 100644 index 00000000..83e6b136 --- /dev/null +++ b/migrations/20240903070800_add_new_campaign_states/migration.sql @@ -0,0 +1,16 @@ +/* + Warnings: + + - The values [initial,pending_validation,approved,rejected,active_pending_validation,disabled,error] on the enum `campaign_state` will be removed. If these variants are still used in the database, this will fail. + +*/ +-- AlterEnum +BEGIN; +CREATE TYPE "campaign_state_new" AS ENUM ('draft', 'active', 'complete', 'partially_financed', 'paused', 'suspended', 'blocked', 'deleted'); +ALTER TABLE "campaigns" ALTER COLUMN "state" DROP DEFAULT; +ALTER TABLE "campaigns" ALTER COLUMN "state" TYPE "campaign_state_new" USING ("state"::text::"campaign_state_new"); +ALTER TYPE "campaign_state" RENAME TO "campaign_state_old"; +ALTER TYPE "campaign_state_new" RENAME TO "campaign_state"; +DROP TYPE "campaign_state_old"; +ALTER TABLE "campaigns" ALTER COLUMN "state" SET DEFAULT 'draft'; +COMMIT; diff --git a/podkrepi.dbml b/podkrepi.dbml index 316d0752..dc65fb35 100644 --- a/podkrepi.dbml +++ b/podkrepi.dbml @@ -642,17 +642,13 @@ Enum PersonRelation { } Enum CampaignState { - initial draft - pending_validation - approved - rejected active - active_pending_validation - suspended complete - disabled - error + partially_financed + paused + suspended + blocked deleted } diff --git a/schema.prisma b/schema.prisma index 70d0c593..a7da1904 100644 --- a/schema.prisma +++ b/schema.prisma @@ -725,24 +725,18 @@ enum PersonRelation { colleague myself myorg - @@map("person_relation") } enum CampaignState { - initial draft - pending_validation - approved - rejected active - active_pending_validation - suspended complete - disabled - error + partially_financed + paused + suspended + blocked deleted - @@map("campaign_state") }