| 1 | 'use server' |
| 2 | |
| 3 | import { and, eq } from 'drizzle-orm' |
| 4 | // import { PROJECTS_CACHE_TAG } from '@/api/projects/service' |
| 5 | import { authedActionClient } |
| 6 | import { titleToSlug } |
| 7 | import { db } |
| 8 | import { projects, requirements |
| 9 | import { createProjectSchema } |
| 10 | |
| 11 | export const createProjectAction = |
| 12 | .inputSchema(createProjectSchema) |
| 13 | .action( |
| 14 | async ({ |
| 15 | parsedInput: { organizationId, |
| 16 | ctx: { orgMember, |
| 17 | }) => { |
| 18 | if (!role.authorize |
| 19 | throw new Error( |
| 20 | } |
| 21 | |
| 22 | if (orgMember.organizationId |
| 23 | throw new Error( |
| 24 | } |
| 25 | const { slugified, |
| 26 | |
| 27 | const project = |
| 28 | const [projectWithSlug] |
| 29 | .select() |
| 30 | .from(projects) |
| 31 | .where( |
| 32 | and( |
| 33 | eq(projects.organizationId |
| 34 | eq(projects.slug |
| 35 | ) |
| 36 | ) |
| 37 | const [project] |
| 38 | .insert(projects) |
| 39 | .values({ |
| 40 | name, |
| 41 | slug: projectWithSlug ? |
| 42 | description: description || |
| 43 | organizationId, |
| 44 | dueDate: dueDate ?? |
| 45 | }) |
| 46 | .returning() |
| 47 | |
| 48 | // This is the requirement called "General Work" |
| 49 | await tx.insert |
| 50 | projectId: project!.id |
| 51 | slug: 'saturn_default_general_work', |
| 52 | title: 'General Work', |
| 53 | body: '<h1> This is a default requirement generated by Saturn to categorize under General Work <h1>', |
| 54 | status: 'client_accepted', |
| 55 | authorId: orgMember.id |
| 56 | }) |
| 57 | |
| 58 | return project |
| 59 | }) |
| 60 | |
| 61 | // revalidateTag(PROJECTS_CACHE_TAG,"max") |
| 62 | return project |
| 63 | } |
| 64 | ) |