Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add new campaign states #672

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
6 changes: 3 additions & 3 deletions apps/api/src/campaign/campaign.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -81,7 +81,7 @@ export class CampaignService {

async listAllCampaigns(): Promise<AdminCampaignListItem[]> {
const campaigns = await this.prisma.campaign.findMany({
where: { NOT: { state: { in: [CampaignState.deleted] } } },
where: { NOT: { state: { in: [CampaignState.draft] } } },
orderBy: {
updatedAt: 'desc',
},
Expand Down Expand Up @@ -611,7 +611,7 @@ export class CampaignService {
}

async canAcceptDonations(campaign: Campaign): Promise<boolean> {
const validStates: CampaignState[] = [CampaignState.active, CampaignState.approved]
const validStates: CampaignState[] = [CampaignState.active]
if (campaign.allowDonationOnComplete) {
validStates.push(CampaignState.complete)
}
Expand Down
16 changes: 16 additions & 0 deletions migrations/20240903070800_add_new_campaign_states/migration.sql
Original file line number Diff line number Diff line change
@@ -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;
12 changes: 4 additions & 8 deletions podkrepi.dbml
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
14 changes: 4 additions & 10 deletions schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down
Loading