fix: replace remaining d1 transactions
This commit is contained in:
@@ -157,8 +157,8 @@ export const actions: Actions = {
|
|||||||
if (contact.isPrimary) return message(form, 'Contact is already primary.');
|
if (contact.isPrimary) return message(form, 'Contact is already primary.');
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
await db.transaction(async (tx) => {
|
await db.batch([
|
||||||
await tx
|
db
|
||||||
.update(contacts)
|
.update(contacts)
|
||||||
.set({ isPrimary: false, updatedAt: now })
|
.set({ isPrimary: false, updatedAt: now })
|
||||||
.where(
|
.where(
|
||||||
@@ -168,9 +168,9 @@ export const actions: Actions = {
|
|||||||
eq(contacts.isPrimary, true),
|
eq(contacts.isPrimary, true),
|
||||||
isNull(contacts.archivedAt)
|
isNull(contacts.archivedAt)
|
||||||
)
|
)
|
||||||
);
|
),
|
||||||
|
|
||||||
await tx
|
db
|
||||||
.update(contacts)
|
.update(contacts)
|
||||||
.set({ isPrimary: true, updatedAt: now })
|
.set({ isPrimary: true, updatedAt: now })
|
||||||
.where(
|
.where(
|
||||||
@@ -180,8 +180,8 @@ export const actions: Actions = {
|
|||||||
eq(contacts.organizationId, activeOrganizationId),
|
eq(contacts.organizationId, activeOrganizationId),
|
||||||
isNull(contacts.archivedAt)
|
isNull(contacts.archivedAt)
|
||||||
)
|
)
|
||||||
);
|
)
|
||||||
});
|
]);
|
||||||
|
|
||||||
return message(form, 'Primary contact updated.');
|
return message(form, 'Primary contact updated.');
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ export const POST: RequestHandler = async ({ locals, request }) => {
|
|||||||
const id = crypto.randomUUID();
|
const id = crypto.randomUUID();
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
|
|
||||||
await db.transaction(async (tx) => {
|
await db.batch([
|
||||||
await tx.insert(organizations).values({
|
db.insert(organizations).values({
|
||||||
id,
|
id,
|
||||||
name: parsed.data.name,
|
name: parsed.data.name,
|
||||||
addressLine1: parsed.data.addressLine1,
|
addressLine1: parsed.data.addressLine1,
|
||||||
@@ -43,16 +43,16 @@ export const POST: RequestHandler = async ({ locals, request }) => {
|
|||||||
bankSwift: parsed.data.bankSwift || null,
|
bankSwift: parsed.data.bankSwift || null,
|
||||||
createdAt: now,
|
createdAt: now,
|
||||||
updatedAt: now
|
updatedAt: now
|
||||||
});
|
}),
|
||||||
|
|
||||||
await tx.insert(organizationMemberships).values({
|
db.insert(organizationMemberships).values({
|
||||||
organizationId: id,
|
organizationId: id,
|
||||||
userId: locals.user.id,
|
userId: locals.user.id,
|
||||||
role: 'admin',
|
role: 'admin',
|
||||||
createdAt: now,
|
createdAt: now,
|
||||||
updatedAt: now
|
updatedAt: now
|
||||||
});
|
})
|
||||||
});
|
]);
|
||||||
|
|
||||||
await setActiveOrganization(locals, id);
|
await setActiveOrganization(locals, id);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user