-
Notifications
You must be signed in to change notification settings - Fork 1
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
1ad2c7f
commit f5cefba
Showing
5 changed files
with
135 additions
and
80 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 |
---|---|---|
@@ -1,15 +1,24 @@ | ||
import { prisma } from "@/db"; | ||
import { trace } from "@opentelemetry/api"; | ||
import type { EmailConfirmationToken } from "@prisma/client"; | ||
|
||
export const getEmailConfirmationToken = async ( | ||
token: EmailConfirmationToken["token"], | ||
) => { | ||
return prisma.emailConfirmationToken.findUnique({ | ||
where: { | ||
token, | ||
expires: { | ||
gt: new Date(), | ||
}, | ||
}, | ||
}); | ||
return await trace | ||
.getTracer("sam") | ||
.startActiveSpan("getEmailConfirmationToken", async (span) => { | ||
try { | ||
return prisma.emailConfirmationToken.findUnique({ | ||
where: { | ||
token, | ||
expires: { | ||
gt: new Date(), | ||
}, | ||
}, | ||
}); | ||
} finally { | ||
span.end(); | ||
} | ||
}); | ||
}; |
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,42 +1,59 @@ | ||
import { prisma } from "@/db"; | ||
import { trace } from "@opentelemetry/api"; | ||
import type { User } from "@prisma/client"; | ||
|
||
export const getUsersWithEntities = async () => { | ||
const [users, entities] = await Promise.all([ | ||
prisma.user.findMany({ | ||
include: { | ||
accounts: true, | ||
}, | ||
}), | ||
return await trace | ||
.getTracer("sam") | ||
.startActiveSpan("getUsersWithEntities", async (span) => { | ||
try { | ||
const [users, entities] = await Promise.all([ | ||
prisma.user.findMany({ | ||
include: { | ||
accounts: true, | ||
}, | ||
}), | ||
|
||
prisma.entity.findMany(), | ||
]); | ||
prisma.entity.findMany(), | ||
]); | ||
|
||
const enrichedUsers = users.map((user) => { | ||
const entity = entities.find( | ||
(entity) => entity.discordId === user.accounts[0].providerAccountId, | ||
); | ||
const enrichedUsers = users.map((user) => { | ||
const entity = entities.find( | ||
(entity) => entity.discordId === user.accounts[0].providerAccountId, | ||
); | ||
|
||
if (!entity) | ||
return { | ||
user, | ||
discordId: user.accounts[0].providerAccountId, | ||
}; | ||
if (!entity) | ||
return { | ||
user, | ||
discordId: user.accounts[0].providerAccountId, | ||
}; | ||
|
||
return { | ||
user, | ||
discordId: user.accounts[0].providerAccountId, | ||
entity, | ||
}; | ||
}); | ||
return { | ||
user, | ||
discordId: user.accounts[0].providerAccountId, | ||
entity, | ||
}; | ||
}); | ||
|
||
return enrichedUsers; | ||
return enrichedUsers; | ||
} finally { | ||
span.end(); | ||
} | ||
}); | ||
}; | ||
|
||
export const getUserById = async (id: User["id"]) => { | ||
return prisma.user.findUnique({ | ||
where: { | ||
id, | ||
}, | ||
}); | ||
return await trace | ||
.getTracer("sam") | ||
.startActiveSpan("getUserById", async (span) => { | ||
try { | ||
return prisma.user.findUnique({ | ||
where: { | ||
id, | ||
}, | ||
}); | ||
} finally { | ||
span.end(); | ||
} | ||
}); | ||
}; |