feat: monorepo
This commit is contained in:
63
packages/db/src/repository/cardComment.repo.ts
Normal file
63
packages/db/src/repository/cardComment.repo.ts
Normal file
@@ -0,0 +1,63 @@
|
||||
import type { SupabaseClient } from "@supabase/supabase-js";
|
||||
|
||||
import type { Database } from "@kan/db/types/database.types";
|
||||
import { generateUID } from "@kan/utils";
|
||||
|
||||
export const create = async (
|
||||
db: SupabaseClient<Database>,
|
||||
commentInput: {
|
||||
cardId: number;
|
||||
comment: string;
|
||||
createdBy: string;
|
||||
},
|
||||
) => {
|
||||
const { data } = await db
|
||||
.from("card_comments")
|
||||
.insert({
|
||||
publicId: generateUID(),
|
||||
comment: commentInput.comment,
|
||||
createdBy: commentInput.createdBy,
|
||||
cardId: commentInput.cardId,
|
||||
})
|
||||
.select(`id, publicId, comment`)
|
||||
.limit(1)
|
||||
.single();
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
export const getByPublicId = async (
|
||||
db: SupabaseClient<Database>,
|
||||
publicId: string,
|
||||
) => {
|
||||
const { data } = await db
|
||||
.from("card_comments")
|
||||
.select(`id, publicId, comment, createdBy`)
|
||||
.eq("publicId", publicId)
|
||||
.limit(1)
|
||||
.single();
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
export const update = async (
|
||||
db: SupabaseClient<Database>,
|
||||
commentInput: {
|
||||
id: number;
|
||||
comment: string;
|
||||
},
|
||||
) => {
|
||||
const { data } = await db
|
||||
.from("card_comments")
|
||||
.update({
|
||||
comment: commentInput.comment,
|
||||
updatedAt: new Date().toISOString(),
|
||||
})
|
||||
.eq("id", commentInput.id)
|
||||
.select(`id, publicId, comment`)
|
||||
.limit(1)
|
||||
.order("id", { ascending: false })
|
||||
.single();
|
||||
|
||||
return data;
|
||||
};
|
||||
Reference in New Issue
Block a user