| 11 | export type Gitlab = typeof gitlab.$inferSelect; |
| 12 | |
| 13 | export const createGitlab = async ( |
| 14 | input: z.infer<typeof apiCreateGitlab>, |
| 15 | organizationId: string, |
| 16 | userId: string, |
| 17 | ) => { |
| 18 | return await db.transaction(async (tx) => { |
| 19 | const newGitProvider = await tx |
| 20 | .insert(gitProvider) |
| 21 | .values({ |
| 22 | providerType: "gitlab", |
| 23 | organizationId: organizationId, |
| 24 | name: input.name, |
| 25 | userId: userId, |
| 26 | }) |
| 27 | .returning() |
| 28 | .then((response) => response[0]); |
| 29 | |
| 30 | if (!newGitProvider) { |
| 31 | throw new TRPCError({ |
| 32 | code: "BAD_REQUEST", |
| 33 | message: "Error creating the Git provider", |
| 34 | }); |
| 35 | } |
| 36 | |
| 37 | await tx |
| 38 | .insert(gitlab) |
| 39 | .values({ |
| 40 | ...input, |
| 41 | gitProviderId: newGitProvider?.gitProviderId, |
| 42 | }) |
| 43 | .returning() |
| 44 | .then((response) => response[0]); |
| 45 | }); |
| 46 | }; |
| 47 | |
| 48 | export const findGitlabById = async (gitlabId: string) => { |
| 49 | const gitlabProviderResult = await db.query.gitlab.findFirst({ |