56 lines
1.5 KiB
TypeScript
56 lines
1.5 KiB
TypeScript
import express from "express";
|
|
import u from "@/utils";
|
|
import { z } from "zod";
|
|
import { success } from "@/lib/responseFormat";
|
|
import { validateFields } from "@/middleware/middleware";
|
|
const router = express.Router();
|
|
import { flowDataSchema } from "@/agents/productionAgent/tools";
|
|
|
|
export default router.post(
|
|
"/",
|
|
validateFields({
|
|
projectId: z.number(),
|
|
episodesId: z.number(),
|
|
data: flowDataSchema,
|
|
}),
|
|
async (req, res) => {
|
|
const {
|
|
data,
|
|
projectId,
|
|
episodesId,
|
|
}: {
|
|
data: z.infer<typeof flowDataSchema>;
|
|
projectId: number;
|
|
episodesId: number;
|
|
} = req.body;
|
|
const sqlData = await u.db("o_agentWorkData").where("projectId", String(projectId)).andWhere("episodesId", String(episodesId)).first();
|
|
if (data.storyboard && data.storyboard.length)
|
|
await Promise.all(
|
|
data.storyboard.map(async (i, index) => {
|
|
await u
|
|
.db("o_storyboard")
|
|
.where("id", i.id)
|
|
.update({
|
|
index: index + 1,
|
|
});
|
|
}),
|
|
);
|
|
if (!sqlData) {
|
|
await u.db("o_agentWorkData").insert({
|
|
projectId,
|
|
episodesId,
|
|
data: JSON.stringify(data),
|
|
});
|
|
} else {
|
|
await u
|
|
.db("o_agentWorkData")
|
|
.where("projectId", String(projectId))
|
|
.andWhere("episodesId", String(episodesId))
|
|
.update({
|
|
data: JSON.stringify(data),
|
|
});
|
|
}
|
|
return res.status(200).send(success());
|
|
},
|
|
);
|