fix: cleanup drizzle refactor
This commit is contained in:
@@ -247,7 +247,7 @@ export const boardRouter = createTRPCRouter({
|
||||
|
||||
const listIds = board.lists.map((list) => list.id);
|
||||
|
||||
const deletedAt = new Date().toISOString();
|
||||
const deletedAt = new Date();
|
||||
|
||||
await boardRepo.softDelete(ctx.db, {
|
||||
boardId: board.id,
|
||||
|
||||
@@ -61,7 +61,7 @@ export const cardRouter = createTRPCRouter({
|
||||
index = lastCard.index + 1;
|
||||
}
|
||||
|
||||
const newCard = await cardRepo.create(ctx.drizzleDb, {
|
||||
const newCard = await cardRepo.create(ctx.db, {
|
||||
title: input.title,
|
||||
description: input.description,
|
||||
createdBy: userId,
|
||||
@@ -83,7 +83,7 @@ export const cardRouter = createTRPCRouter({
|
||||
input.labelPublicIds,
|
||||
);
|
||||
|
||||
if (!labels?.length)
|
||||
if (!labels.length)
|
||||
throw new TRPCError({
|
||||
message: `Labels with public IDs (${input.labelPublicIds.join(", ")}) not found`,
|
||||
code: "NOT_FOUND",
|
||||
@@ -99,7 +99,7 @@ export const cardRouter = createTRPCRouter({
|
||||
labelsInsert,
|
||||
);
|
||||
|
||||
if (!cardLabels?.length)
|
||||
if (!cardLabels.length)
|
||||
throw new TRPCError({
|
||||
message: `Failed to create card label relationships`,
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
@@ -121,7 +121,7 @@ export const cardRouter = createTRPCRouter({
|
||||
input.memberPublicIds,
|
||||
);
|
||||
|
||||
if (!members?.length)
|
||||
if (!members.length)
|
||||
throw new TRPCError({
|
||||
message: `Members with public IDs (${input.memberPublicIds.join(", ")}) not found`,
|
||||
code: "NOT_FOUND",
|
||||
@@ -138,7 +138,7 @@ export const cardRouter = createTRPCRouter({
|
||||
membersInsert,
|
||||
);
|
||||
|
||||
if (!cardMembers?.length)
|
||||
if (!cardMembers.length)
|
||||
throw new TRPCError({
|
||||
message: `Failed to create card member relationships`,
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
@@ -672,13 +672,13 @@ export const cardRouter = createTRPCRouter({
|
||||
input.cardPublicId,
|
||||
);
|
||||
|
||||
if (!card?.list?.id)
|
||||
if (!card?.list.id)
|
||||
throw new TRPCError({
|
||||
message: `Card with public ID ${input.cardPublicId} not found`,
|
||||
code: "NOT_FOUND",
|
||||
});
|
||||
|
||||
const deletedAt = new Date().toISOString();
|
||||
const deletedAt = new Date();
|
||||
|
||||
const deletedCard = await cardRepo.softDelete(ctx.db, {
|
||||
cardId: card.id,
|
||||
@@ -692,7 +692,7 @@ export const cardRouter = createTRPCRouter({
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
});
|
||||
|
||||
await cardRepo.shiftIndex(ctx.db, {
|
||||
await cardRepo.shiftIndex(ctx.supabaseClient, {
|
||||
listId: card.list.id,
|
||||
cardIndex: card.index,
|
||||
});
|
||||
@@ -770,7 +770,7 @@ export const cardRouter = createTRPCRouter({
|
||||
newIndex = lastCardIndex !== undefined ? lastCardIndex + 1 : 0;
|
||||
}
|
||||
|
||||
const { success } = await cardRepo.reorder(ctx.db, {
|
||||
const { success } = await cardRepo.reorder(ctx.supabaseClient, {
|
||||
currentListId: currentList.id,
|
||||
newListId: newList.id,
|
||||
currentIndex,
|
||||
|
||||
@@ -209,7 +209,7 @@ export const importRouter = createTRPCRouter({
|
||||
|
||||
const newLabels = await labelRepo.bulkCreate(ctx.db, labelsInsert);
|
||||
|
||||
if (newLabels?.length)
|
||||
if (newLabels.length)
|
||||
createdLabels = newLabels
|
||||
.map((label, index) => ({
|
||||
id: label.id,
|
||||
|
||||
@@ -93,7 +93,7 @@ export const listRouter = createTRPCRouter({
|
||||
code: "NOT_FOUND",
|
||||
});
|
||||
|
||||
const result = await listRepo.reorder(ctx.db, {
|
||||
const result = await listRepo.reorder(ctx.supabaseClient, {
|
||||
boardPublicId: list.boardId,
|
||||
listPublicId: list.id,
|
||||
currentIndex: input.currentIndex,
|
||||
@@ -142,7 +142,7 @@ export const listRouter = createTRPCRouter({
|
||||
code: "NOT_FOUND",
|
||||
});
|
||||
|
||||
const deletedAt = new Date().toISOString();
|
||||
const deletedAt = new Date();
|
||||
|
||||
const deletedList = await listRepo.softDeleteById(ctx.db, {
|
||||
listId: list.id,
|
||||
@@ -176,7 +176,7 @@ export const listRouter = createTRPCRouter({
|
||||
|
||||
await activityRepo.bulkCreate(ctx.db, activities);
|
||||
|
||||
await listRepo.shiftIndex(ctx.db, {
|
||||
await listRepo.shiftIndex(ctx.supabaseClient, {
|
||||
boardId: list.boardId,
|
||||
listIndex: list.index,
|
||||
});
|
||||
@@ -203,7 +203,7 @@ export const listRouter = createTRPCRouter({
|
||||
.output(z.custom<Awaited<ReturnType<typeof listRepo.update>>>())
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const result = await listRepo.update(
|
||||
ctx.db,
|
||||
ctx.supabaseClient,
|
||||
{ name: input.name },
|
||||
{ listPublicId: input.listPublicId },
|
||||
);
|
||||
|
||||
@@ -59,7 +59,7 @@ export const memberRouter = createTRPCRouter({
|
||||
});
|
||||
|
||||
const isInvitedEmailAlreadyMember = workspace.members.some(
|
||||
(member) => member.user?.email === input.email,
|
||||
(member) => member.user.email === input.email,
|
||||
);
|
||||
|
||||
if (isInvitedEmailAlreadyMember) {
|
||||
@@ -78,7 +78,7 @@ export const memberRouter = createTRPCRouter({
|
||||
if (existingUser) {
|
||||
invitedUserId = existingUser.id;
|
||||
|
||||
const magicLink = await ctx.db.auth.admin.generateLink({
|
||||
const magicLink = await ctx.supabaseClient.auth.admin.generateLink({
|
||||
type: "magiclink",
|
||||
email: input.email,
|
||||
options: {
|
||||
@@ -89,7 +89,7 @@ export const memberRouter = createTRPCRouter({
|
||||
hashedToken = magicLink.data.properties?.hashed_token;
|
||||
verificationType = magicLink.data.properties?.verification_type;
|
||||
} else {
|
||||
const invite = await ctx.db.auth.admin.generateLink({
|
||||
const invite = await ctx.supabaseClient.auth.admin.generateLink({
|
||||
type: "invite",
|
||||
email: input.email,
|
||||
options: {
|
||||
@@ -117,7 +117,13 @@ export const memberRouter = createTRPCRouter({
|
||||
stripeCustomerId: stripeCustomer.id,
|
||||
});
|
||||
|
||||
invitedUserId = newUser?.id;
|
||||
if (!newUser)
|
||||
throw new TRPCError({
|
||||
message: `Failed to create a new user for email ${invitedUserEmail}`,
|
||||
code: "INTERNAL_SERVER_ERROR",
|
||||
});
|
||||
|
||||
invitedUserId = newUser.id;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -211,7 +217,7 @@ export const memberRouter = createTRPCRouter({
|
||||
|
||||
const deletedMember = await memberRepo.softDelete(ctx.db, {
|
||||
memberId: member.id,
|
||||
deletedAt: new Date().toISOString(),
|
||||
deletedAt: new Date(),
|
||||
deletedBy: userId,
|
||||
});
|
||||
|
||||
|
||||
@@ -82,7 +82,7 @@ export const bulkCreateCardLabelRelationships = async (
|
||||
labelId: number;
|
||||
}[],
|
||||
) => {
|
||||
const [result] = await db
|
||||
const result = await db
|
||||
.insert(cardsToLabels)
|
||||
.values(cardLabelRelationshipInput)
|
||||
.returning();
|
||||
@@ -97,7 +97,7 @@ export const bulkCreateCardWorkspaceMemberRelationships = async (
|
||||
workspaceMemberId: number;
|
||||
}[],
|
||||
) => {
|
||||
const [result] = await db
|
||||
const result = await db
|
||||
.insert(cardToWorkspaceMembers)
|
||||
.values(cardWorkspaceMemberRelationshipInput)
|
||||
.returning();
|
||||
@@ -189,7 +189,7 @@ export const bulkCreate = async (
|
||||
importId?: number;
|
||||
}[],
|
||||
) => {
|
||||
const [result] = await db.insert(cards).values(cardInput).returning({
|
||||
const result = await db.insert(cards).values(cardInput).returning({
|
||||
id: cards.id,
|
||||
});
|
||||
|
||||
@@ -551,7 +551,7 @@ export const hardDeleteCardLabelRelationship = async (
|
||||
)
|
||||
.returning();
|
||||
|
||||
return { data: result };
|
||||
return result;
|
||||
};
|
||||
|
||||
export const hardDeleteAllCardLabelRelationships = async (
|
||||
|
||||
@@ -124,12 +124,13 @@ export const softDeleteAllByBoardId = async (
|
||||
db: dbClient,
|
||||
args: {
|
||||
boardId: number;
|
||||
deletedAt: Date;
|
||||
deletedBy: string;
|
||||
},
|
||||
) => {
|
||||
const [result] = await db
|
||||
.update(lists)
|
||||
.set({ deletedAt: new Date(), deletedBy: args.deletedBy })
|
||||
.set({ deletedAt: args.deletedAt, deletedBy: args.deletedBy })
|
||||
.where(and(eq(lists.boardId, args.boardId), isNull(lists.deletedAt)))
|
||||
.returning({
|
||||
id: lists.id,
|
||||
@@ -142,12 +143,13 @@ export const softDeleteById = async (
|
||||
db: dbClient,
|
||||
args: {
|
||||
listId: number;
|
||||
deletedAt: Date;
|
||||
deletedBy: string;
|
||||
},
|
||||
) => {
|
||||
const [updatedList] = await db
|
||||
.update(lists)
|
||||
.set({ deletedAt: new Date(), deletedBy: args.deletedBy })
|
||||
.set({ deletedAt: args.deletedAt, deletedBy: args.deletedBy })
|
||||
.where(and(eq(lists.id, args.listId), isNull(lists.deletedAt)))
|
||||
.returning({
|
||||
id: lists.id,
|
||||
|
||||
@@ -56,12 +56,13 @@ export const softDelete = async (
|
||||
db: dbClient,
|
||||
args: {
|
||||
memberId: number;
|
||||
deletedAt: Date;
|
||||
deletedBy: string;
|
||||
},
|
||||
) => {
|
||||
const [result] = await db
|
||||
.update(workspaceMembers)
|
||||
.set({ deletedAt: new Date(), deletedBy: args.deletedBy })
|
||||
.set({ deletedAt: args.deletedAt, deletedBy: args.deletedBy })
|
||||
.where(
|
||||
and(
|
||||
eq(workspaceMembers.id, args.memberId),
|
||||
|
||||
@@ -27,15 +27,20 @@ export const getByEmail = (db: dbClient, email: string) => {
|
||||
});
|
||||
};
|
||||
|
||||
export const create = (
|
||||
export const create = async (
|
||||
db: dbClient,
|
||||
user: { id: string; email: string; stripeCustomerId: string },
|
||||
) => {
|
||||
return db.insert(users).values({
|
||||
id: user.id,
|
||||
email: user.email,
|
||||
stripeCustomerId: user.stripeCustomerId,
|
||||
});
|
||||
const [result] = await db
|
||||
.insert(users)
|
||||
.values({
|
||||
id: user.id,
|
||||
email: user.email,
|
||||
stripeCustomerId: user.stripeCustomerId,
|
||||
})
|
||||
.returning();
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
export const update = async (
|
||||
|
||||
Reference in New Issue
Block a user