export const insertModpack = command(
ModpackInsertValidator.pick({
...
}),
async (partial) => {
const { data, error } = await tryCatch(async () => {
return await db.insert(Modpack).set(partial).returning({
...
}),
});
if (error || !data) {
throw panic('MNP49G0HQV');
}
posthog.capture({
event: 'Modpack.created',
distincId: profileId.toString()
});
return data;
},
);
…
export const updateModpack = command(
z.object({
id: z.number(),
partial: ModpackUpdateValidator.pick({
...
}),
}),
async ({ id, partial }) => {
const { error } = await tryCatch(async () => {
await db.update(Modpack).set(partial).where(eq(id, Modpack.id));
});
if (error) {
throw panic('MNQHP30B4T');
}
},
);
export const deleteModpack = command(ModpackDeleteValidator, async (partial) => {
const { error } = await tryCatch(async () => {
await db
.delete(Modpack)
.where(and(eq(partial.id, Modpack.id), eq(partial.profileId, Modpack.profileId)));
});
if (error) {
throw panic('MNQHS1M3XD');
}
posthog.capture({
event: 'Modpack.deleted',
distinctId: partial.profileId.toString(),
});
});