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