Skip to content

Commit

Permalink
feat: 템플릿 생성 api 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
delphox60 committed Aug 11, 2024
1 parent 717678a commit 0734dc6
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/lib/db/schema/templates.query.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
"use server";
import { eq } from "drizzle-orm";
import { nanoid } from "nanoid";

import { db } from "~/lib/db";
import { templates } from "~/lib/db/schema/templates";

type CreateTemplateParams = {
title: string;
description?: string;
customFields?: Record<string, any>; // JSON data
};

type UpdateTemplateParams = {
id: string;
title?: string;
Expand Down Expand Up @@ -56,3 +63,25 @@ async function deleteTemplate(id: string): Promise<void> {
throw new Error("Could not delete template");
}
}

async function createTemplate(params: CreateTemplateParams): Promise<void> {
const { title, description, customFields } = params;

const id = nanoid();

const currentTimestamp = new Date();

try {
await db.insert(templates).values({
id,
title,
description,
customFields,
createdAt: currentTimestamp,
updatedAt: currentTimestamp,
});
} catch (error) {
console.error("Error creating template:", error);
throw new Error("Could not create template");
}
}

0 comments on commit 0734dc6

Please sign in to comment.