-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add move action * Use transaction * Use cte instead of transaction --------- Co-authored-by: Kalil Smith-Nuevelle <[email protected]>
- Loading branch information
Showing
12 changed files
with
75 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as z from "zod"; | ||
|
||
import { MoveHorizontal } from "ui/icon"; | ||
|
||
import { defineAction } from "../types"; | ||
|
||
export const action = defineAction({ | ||
name: "move", | ||
config: z.object({ | ||
stage: z.string().describe("Destination stage"), | ||
}), | ||
description: "Move a pub to a different stage", | ||
runParameters: z.object({}).optional(), | ||
pubFields: [], | ||
icon: MoveHorizontal, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
"use server"; | ||
|
||
import { logger } from "logger"; | ||
|
||
import type { action } from "./action"; | ||
import type { PubsId } from "~/kysely/types/public/Pubs"; | ||
import type { StagesId } from "~/kysely/types/public/Stages"; | ||
import { db } from "~/kysely/database"; | ||
import { defineRun } from "../types"; | ||
|
||
export const run = defineRun<typeof action>(async ({ pub, config, stageId }) => { | ||
try { | ||
await db | ||
.with("leave-stage", (db) => | ||
db | ||
.deleteFrom("PubsInStages") | ||
.where("pubId", "=", pub.id as PubsId) | ||
.where("stageId", "=", stageId) | ||
) | ||
.insertInto("PubsInStages") | ||
.values({ | ||
pubId: pub.id as PubsId, | ||
stageId: config.stage as StagesId, | ||
}) | ||
.execute(); | ||
} catch (error) { | ||
logger.error({ msg: "move", error }); | ||
return { | ||
title: "Failed to move pub", | ||
error: "An error occured while moving the pub", | ||
cause: error, | ||
}; | ||
} | ||
|
||
logger.info({ msg: "move", pub, config }); | ||
|
||
return { | ||
success: true, | ||
report: "Pub moved", | ||
data: {}, | ||
}; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { run as pdf } from "./pdf/run"; | ||
export { run as email } from "./email/run"; | ||
export { run as log } from "./log/run"; | ||
export { run as move } from "./move/run"; | ||
export { run as pushToV6 } from "./pushToV6/run"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ enum Action { | |
pdf = "pdf", | ||
email = "email", | ||
pushToV6 = "pushToV6", | ||
move = "move", | ||
} | ||
|
||
export default Action; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
core/prisma/migrations/20240506184830_add_move_action/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterEnum | ||
ALTER TYPE "Action" ADD VALUE 'move'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -347,6 +347,7 @@ enum Action { | |
pushToV6 | ||
move | ||
} | ||
|
||
model Rule { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ export { | |
Mail, | ||
Menu, | ||
MoreVertical, | ||
MoveHorizontal, | ||
Pencil, | ||
Plus, | ||
Play, | ||
|