mirror of
https://github.com/p-stream/backend.git
synced 2026-03-21 18:07:15 +00:00
Fixes both the stuff pointed out by qudo
This commit is contained in:
parent
ed08f2daab
commit
2e3de58a9c
2 changed files with 18 additions and 7 deletions
|
|
@ -40,12 +40,23 @@ export default defineEventHandler(async event => {
|
|||
const validatedBody = updateSessionSchema.parse(body);
|
||||
|
||||
// Use update return value directly — no redundant findUnique
|
||||
const updatedSession = validatedBody.deviceName
|
||||
? await prisma.sessions.update({
|
||||
where: { id: sessionId },
|
||||
data: { device: validatedBody.deviceName },
|
||||
})
|
||||
: targetedSession;
|
||||
let updatedSession;
|
||||
try {
|
||||
updatedSession = validatedBody.deviceName
|
||||
? await prisma.sessions.update({
|
||||
where: { id: sessionId },
|
||||
data: { device: validatedBody.deviceName },
|
||||
})
|
||||
: targetedSession;
|
||||
} catch (err: any) {
|
||||
if (err.code === 'P2002') {
|
||||
throw createError({
|
||||
statusCode: 409,
|
||||
message: 'A session with this device name already exists',
|
||||
});
|
||||
}
|
||||
throw err;
|
||||
}
|
||||
|
||||
return {
|
||||
id: updatedSession.id,
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ export function useAuth() {
|
|||
// Atomic upsert — backed by @@unique([user, device]) in schema
|
||||
return await prisma.sessions.upsert({
|
||||
where: {
|
||||
sessions_user_device_unique: { user, device },
|
||||
user_device: { user, device },
|
||||
},
|
||||
update: {
|
||||
id: uuidv7(),
|
||||
|
|
|
|||
Loading…
Reference in a new issue