Skip to content

Commit a825496

Browse files
authored
Merge pull request #282 from SCVApp/master
query log fix
2 parents 565d990 + 6f4ae93 commit a825496

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

src/lockers/lockers.service.ts

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ export class LockersService {
195195

196196
const success = await this.openLocker(selectedLocker);
197197
if (!success) {
198-
await this.lockersUsersRepository.delete({
199-
user,
200-
locker: selectedLocker,
201-
});
198+
await this.lockersUsersRepository.query(
199+
`DELETE FROM lockers_users WHERE id = (SELECT id FROM lockers_users WHERE user_id = $1 AND locker_id = $2 ORDER BY start_time DESC LIMIT 1)`,
200+
[user.id, selectedLocker.id],
201+
);
202202
throw new InternalServerErrorException('Failed to open locker');
203203
}
204204
return { success: true };
@@ -232,14 +232,10 @@ export class LockersService {
232232
if (!success) {
233233
throw new InternalServerErrorException('Failed to open locker');
234234
}
235-
await this.lockersUsersRepository.update(
236-
{
237-
user,
238-
locker: activeLocker,
239-
},
240-
{
241-
end_time: new Date(),
242-
},
235+
236+
await this.lockersUsersRepository.query(
237+
`UPDATE lockers_users SET end_time = NOW() WHERE id = (SELECT id FROM lockers_users WHERE user_id = $1 AND locker_id = $2 ORDER BY start_time DESC LIMIT 1)`,
238+
[user.id, activeLocker.id],
243239
);
244240
return { success: true };
245241
}
@@ -302,13 +298,9 @@ export class LockersService {
302298
if (!success) {
303299
throw new InternalServerErrorException('Failed to open locker');
304300
}
305-
await this.lockersUsersRepository.update(
306-
{
307-
locker,
308-
},
309-
{
310-
end_time: new Date(),
311-
},
301+
await this.lockersUsersRepository.query(
302+
`UPDATE lockers_users SET end_time = NOW() WHERE id = (SELECT id FROM lockers_users WHERE locker_id = $1 ORDER BY start_time DESC LIMIT 1)`,
303+
[locker.id],
312304
);
313305
}
314306

0 commit comments

Comments
 (0)