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
0e6e8cc
commit 734f9ed
Showing
6 changed files
with
100 additions
and
122 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
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 |
---|---|---|
@@ -1,13 +1,27 @@ | ||
const UtilsApiVersionGet = async ({ tx, spaceId, userId }) => { | ||
// Important: we need to make sure that the `spaceId` provided in the query is also owned by user | ||
const prismaReplicacheSpaceFindFirst = await tx.space.findFirst({ | ||
const prismaSpaceFindFirst = await tx.space.findFirst({ | ||
where: { AND: [{ spaceId }, { userId }] }, | ||
select: { version: true } | ||
}) | ||
|
||
if (!prismaReplicacheSpaceFindFirst) return { error: `spaceId #${spaceId} not found` } | ||
if (prismaSpaceFindFirst?.version === undefined) { | ||
const prismaSpaceCreateOne = await tx.space.create({ | ||
data: { | ||
// --- PUBLIC ID --- | ||
spaceId, | ||
// --- RELATIONS --- | ||
User: { connect: { userId } }, | ||
// --- FIELDS --- | ||
version: 0 | ||
}, | ||
select: { version: true } | ||
}) | ||
|
||
return { data: prismaReplicacheSpaceFindFirst.version + 1 } | ||
return { data: prismaSpaceCreateOne.version + 1 } | ||
} | ||
|
||
return { data: prismaSpaceFindFirst.version + 1 } | ||
} | ||
|
||
export default UtilsApiVersionGet |
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