Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update Prisma calls to support 2.12+ #881

Merged
merged 4 commits into from
Dec 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"mysql": "^2.18.1",
"mssql": "^6.2.1",
"pg": "^8.2.1",
"@prisma/client": "^2.3.0"
"@prisma/client": "^2.12.0"
},
"devDependencies": {
"@babel/cli": "^7.8.4",
Expand Down
12 changes: 6 additions & 6 deletions src/adapters/prisma/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const Adapter = (config) => {
async function getUser (id) {
debug('GET_USER', id)
try {
return prisma[User].findOne({ where: { id } })
return prisma[User].findUnique({ where: { id } })
} catch (error) {
logger.error('GET_USER_BY_ID_ERROR', error)
return Promise.reject(new Error('GET_USER_BY_ID_ERROR', error))
Expand All @@ -68,7 +68,7 @@ const Adapter = (config) => {
debug('GET_USER_BY_EMAIL', email)
try {
if (!email) { return Promise.resolve(null) }
return prisma[User].findOne({ where: { email } })
return prisma[User].findUnique({ where: { email } })
} catch (error) {
logger.error('GET_USER_BY_EMAIL_ERROR', error)
return Promise.reject(new Error('GET_USER_BY_EMAIL_ERROR', error))
Expand All @@ -78,9 +78,9 @@ const Adapter = (config) => {
async function getUserByProviderAccountId (providerId, providerAccountId) {
debug('GET_USER_BY_PROVIDER_ACCOUNT_ID', providerId, providerAccountId)
try {
const account = await prisma[Account].findOne({ where: { compoundId: getCompoundId(providerId, providerAccountId) } })
const account = await prisma[Account].findUnique({ where: { compoundId: getCompoundId(providerId, providerAccountId) } })
if (!account) { return null }
return prisma[User].findOne({ where: { id: account.userId } })
return prisma[User].findUnique({ where: { id: account.userId } })
} catch (error) {
logger.error('GET_USER_BY_PROVIDER_ACCOUNT_ID_ERROR', error)
return Promise.reject(new Error('GET_USER_BY_PROVIDER_ACCOUNT_ID_ERROR', error))
Expand Down Expand Up @@ -174,7 +174,7 @@ const Adapter = (config) => {
async function getSession (sessionToken) {
debug('GET_SESSION', sessionToken)
try {
const session = await prisma[Session].findOne({ where: { sessionToken } })
const session = await prisma[Session].findUnique({ where: { sessionToken } })

// Check session has not expired (do not return it if it has)
if (session && session.expires && new Date() > session.expires) {
Expand Down Expand Up @@ -280,7 +280,7 @@ const Adapter = (config) => {
// Hash token provided with secret before trying to match it with database
// @TODO Use bcrypt instead of salted SHA-256 hash for token
const hashedToken = createHash('sha256').update(`${token}${secret}`).digest('hex')
const verificationRequest = await prisma[VerificationRequest].findOne({ where: { token: hashedToken } })
const verificationRequest = await prisma[VerificationRequest].findUnique({ where: { token: hashedToken } })

if (verificationRequest && verificationRequest.expires && new Date() > verificationRequest.expires) {
// Delete verification entry so it cannot be used again
Expand Down
12 changes: 6 additions & 6 deletions src/adapters/typeorm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const Adapter = (typeOrmConfig, options = {}) => {
}

try {
return manager.findOne(User, { [idKey]: id })
return manager.findUnique(User, { [idKey]: id })
} catch (error) {
logger.error('GET_USER_BY_ID_ERROR', error)
return Promise.reject(new Error('GET_USER_BY_ID_ERROR', error))
Expand All @@ -155,7 +155,7 @@ const Adapter = (typeOrmConfig, options = {}) => {
debug('GET_USER_BY_EMAIL', email)
try {
if (!email) { return Promise.resolve(null) }
return manager.findOne(User, { email })
return manager.findUnique(User, { email })
} catch (error) {
logger.error('GET_USER_BY_EMAIL_ERROR', error)
return Promise.reject(new Error('GET_USER_BY_EMAIL_ERROR', error))
Expand All @@ -165,9 +165,9 @@ const Adapter = (typeOrmConfig, options = {}) => {
async function getUserByProviderAccountId (providerId, providerAccountId) {
debug('GET_USER_BY_PROVIDER_ACCOUNT_ID', providerId, providerAccountId)
try {
const account = await manager.findOne(Account, { providerId, providerAccountId })
const account = await manager.findUnique(Account, { providerId, providerAccountId })
if (!account) { return null }
return manager.findOne(User, { [idKey]: account.userId })
return manager.findUnique(User, { [idKey]: account.userId })
} catch (error) {
logger.error('GET_USER_BY_PROVIDER_ACCOUNT_ID_ERROR', error)
return Promise.reject(new Error('GET_USER_BY_PROVIDER_ACCOUNT_ID_ERROR', error))
Expand Down Expand Up @@ -227,7 +227,7 @@ const Adapter = (typeOrmConfig, options = {}) => {
async function getSession (sessionToken) {
debug('GET_SESSION', sessionToken)
try {
const session = await manager.findOne(Session, { sessionToken })
const session = await manager.findUnique(Session, { sessionToken })

// Check session has not expired (do not return it if it has)
if (session && session.expires && new Date() > new Date(session.expires)) {
Expand Down Expand Up @@ -327,7 +327,7 @@ const Adapter = (typeOrmConfig, options = {}) => {
// Hash token provided with secret before trying to match it with database
// @TODO Use bcrypt instead of salted SHA-256 hash for token
const hashedToken = createHash('sha256').update(`${token}${secret}`).digest('hex')
const verificationRequest = await manager.findOne(VerificationRequest, { identifier, token: hashedToken })
const verificationRequest = await manager.findUnique(VerificationRequest, { identifier, token: hashedToken })

if (verificationRequest && verificationRequest.expires && new Date() > new Date(verificationRequest.expires)) {
// Delete verification entry so it cannot be used again
Expand Down