feat: change language
This commit is contained in:
@@ -191,6 +191,55 @@ export async function updateSaveTheDateSent({
|
||||
})
|
||||
}
|
||||
|
||||
export async function updateInvitationLanguage({
|
||||
invitationId,
|
||||
language,
|
||||
adminEmail,
|
||||
}: {
|
||||
invitationId: string
|
||||
language: string
|
||||
adminEmail: string
|
||||
}) {
|
||||
return db.transaction().execute(async (trx) => {
|
||||
const invitation = await trx
|
||||
.selectFrom("invitations")
|
||||
.select(["id", "display_name", "language"])
|
||||
.where("id", "=", invitationId)
|
||||
.executeTakeFirst()
|
||||
|
||||
if (!invitation) return null
|
||||
|
||||
const updated = await trx
|
||||
.updateTable("invitations")
|
||||
.set({
|
||||
language,
|
||||
updated_at: new Date(),
|
||||
})
|
||||
.where("id", "=", invitationId)
|
||||
.returning(["id", "language"])
|
||||
.executeTakeFirst()
|
||||
|
||||
if (!updated) return null
|
||||
|
||||
await trx
|
||||
.insertInto("admin_audit_events")
|
||||
.values({
|
||||
admin_email: adminEmail,
|
||||
action: "invitation.language_updated",
|
||||
target_type: "invitation",
|
||||
target_id: invitationId,
|
||||
metadata: {
|
||||
displayName: invitation.display_name,
|
||||
previousLanguage: invitation.language,
|
||||
newLanguage: language,
|
||||
},
|
||||
})
|
||||
.execute()
|
||||
|
||||
return updated
|
||||
})
|
||||
}
|
||||
|
||||
export async function listInvitations(): Promise<InvitationListItem[]> {
|
||||
const invitations = await db
|
||||
.selectFrom("invitations")
|
||||
|
||||
@@ -54,6 +54,14 @@ export const updateSaveTheDateSentSchema = z.object({
|
||||
sent: z.boolean(),
|
||||
})
|
||||
|
||||
export const updateInvitationLanguageSchema = z.object({
|
||||
invitationId: z.uuid(),
|
||||
language: z.enum(supportedLanguageCodes, {
|
||||
error: "Select a supported language",
|
||||
}),
|
||||
})
|
||||
|
||||
export type CreateInvitationInput = z.infer<typeof createInvitationSchema>
|
||||
export type DeleteInvitationInput = z.infer<typeof deleteInvitationSchema>
|
||||
export type UpdateSaveTheDateSentInput = z.infer<typeof updateSaveTheDateSentSchema>
|
||||
export type UpdateInvitationLanguageInput = z.infer<typeof updateInvitationLanguageSchema>
|
||||
|
||||
Reference in New Issue
Block a user