This repository has been archived by the owner on Aug 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba604aa
commit bd1a3af
Showing
2 changed files
with
52 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import prisma from "./prisma"; | ||
|
||
export async function updatePassports(id: string) { | ||
// Fetch passport given id and set activated to true | ||
// Fetch all other passports by that user that are marked activated | ||
// If there are any, mark all of them deactivated | ||
|
||
const passportId = Number(id); | ||
const passport = await prisma.passport.update({ | ||
where: { | ||
id: passportId, | ||
}, | ||
data: { | ||
activated: true, | ||
}, | ||
}); | ||
const ownerId = passport.owner_id; | ||
|
||
const otherPassports = await prisma.passport.findMany({ | ||
where: { | ||
owner_id: ownerId, | ||
activated: true, | ||
NOT: { | ||
id: passportId, | ||
}, | ||
}, | ||
}); | ||
if (otherPassports.length > 0) { | ||
for (const otherPassport of otherPassports) { | ||
await prisma.passport.update({ | ||
where: { | ||
id: otherPassport.id, | ||
}, | ||
data: { | ||
activated: false, | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
return passport; | ||
} |