Skip to content

Commit 85275b5

Browse files
th-236: * correct db request (#278)
1 parent fbbcc52 commit 85275b5

File tree

1 file changed

+29
-12
lines changed

1 file changed

+29
-12
lines changed

backend/src/packages/orders/order.repository.ts

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import { eq } from 'drizzle-orm';
22

33
import { type IRepository } from '~/libs/interfaces/interfaces.js';
44
import { type IDatabase } from '~/libs/packages/database/database.js';
5-
import {
6-
type DatabaseSchema,
7-
schema,
8-
} from '~/libs/packages/database/schema/schema.js';
5+
import { type DatabaseSchema } from '~/libs/packages/database/schema/schema.js';
96

107
import { type UserEntityT } from '../users/users.js';
118
import { combineFilters } from './libs/helpers/combine-filters.js';
@@ -78,11 +75,21 @@ class OrderRepository implements Omit<IRepository, 'find'> {
7875
},
7976
})
8077
.from(this.ordersSchema)
81-
.innerJoin(schema.shifts, eq(this.ordersSchema.shiftId, schema.shifts.id))
82-
.innerJoin(schema.users, eq(schema.shifts.driverId, schema.users.id))
8378
.innerJoin(
84-
schema.drivers,
85-
eq(schema.drivers.userId, schema.shifts.driverId),
79+
this.shiftsSchema,
80+
eq(this.ordersSchema.shiftId, this.shiftsSchema.id),
81+
)
82+
.innerJoin(
83+
this.usersSchema,
84+
eq(this.shiftsSchema.driverId, this.usersSchema.id),
85+
)
86+
.innerJoin(
87+
this.driversSchema,
88+
eq(this.driversSchema.userId, this.shiftsSchema.driverId),
89+
)
90+
.innerJoin(
91+
this.trucksSchema,
92+
eq(this.trucksSchema.id, this.shiftsSchema.truckId),
8693
)
8794
.where(eq(this.ordersSchema.id, id));
8895

@@ -125,11 +132,21 @@ class OrderRepository implements Omit<IRepository, 'find'> {
125132
},
126133
})
127134
.from(this.ordersSchema)
128-
.innerJoin(schema.shifts, eq(this.ordersSchema.shiftId, schema.shifts.id))
129-
.innerJoin(schema.users, eq(schema.shifts.driverId, schema.users.id))
130135
.innerJoin(
131-
schema.drivers,
132-
eq(schema.drivers.userId, schema.shifts.driverId),
136+
this.shiftsSchema,
137+
eq(this.ordersSchema.shiftId, this.shiftsSchema.id),
138+
)
139+
.innerJoin(
140+
this.usersSchema,
141+
eq(this.shiftsSchema.driverId, this.usersSchema.id),
142+
)
143+
.innerJoin(
144+
this.driversSchema,
145+
eq(this.driversSchema.userId, this.shiftsSchema.driverId),
146+
)
147+
.innerJoin(
148+
this.trucksSchema,
149+
eq(this.trucksSchema.id, this.shiftsSchema.truckId),
133150
)
134151
.where(
135152
combineFilters<DatabaseSchema['orders']>(this.ordersSchema, search),

0 commit comments

Comments
 (0)