Changeset 3870834 for database/drizzle
- Timestamp:
- 12/29/25 02:25:26 (6 months ago)
- Branches:
- main
- Children:
- b6e1b3c, dda6f51
- Parents:
- 915ce0f
- File:
-
- 1 edited
-
database/drizzle/queries/builds.ts (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
database/drizzle/queries/builds.ts
r915ce0f r3870834 522 522 523 523 export async function getBuildState(db: Database, userId: number, buildId: number) { 524 const [build] = await db 525 .select({ 526 id: buildsTable.id, 527 userId: buildsTable.userId, 528 isApproved: buildsTable.isApproved, 529 name: buildsTable.name, 530 description: buildsTable.description, 531 totalPrice: buildsTable.totalPrice, 532 }) 533 .from(buildsTable) 534 .where( 535 and( 536 eq(buildsTable.id, buildId), 537 eq(buildsTable.userId, userId) 538 ) 539 ) 540 .limit(1); 541 542 if (!build || build.isApproved) return null; 543 544 const components = await db 545 .select({ componentId: buildComponentsTable.componentId 546 }) 547 .from(buildComponentsTable) 548 .where( 549 eq(buildComponentsTable.buildId, buildId) 550 ); 551 552 return { 553 build, 554 componentIds: components.map(c => c.componentId) 555 }; 556 } 524 return db.transaction(async (tx) => { 525 const [build] = await tx 526 .select({ 527 id: buildsTable.id, 528 userId: buildsTable.userId, 529 isApproved: buildsTable.isApproved, 530 name: buildsTable.name, 531 description: buildsTable.description, 532 totalPrice: buildsTable.totalPrice, 533 }) 534 .from(buildsTable) 535 .where( 536 and( 537 eq(buildsTable.id, buildId), 538 eq(buildsTable.userId, userId) 539 ) 540 ) 541 .limit(1); 542 543 if (!build || build.isApproved) return null; 544 545 const components = await tx 546 .select({ 547 componentId: buildComponentsTable.componentId 548 }) 549 .from(buildComponentsTable) 550 .where( 551 eq(buildComponentsTable.buildId, buildId) 552 ); 553 554 return { 555 build, 556 componentIds: components.map(c => c.componentId) 557 }; 558 }); 559 }
Note:
See TracChangeset
for help on using the changeset viewer.
