-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
This reverts commit ba2e854.
- Loading branch information
1 parent
ba2e854
commit a1b3d86
Showing
5 changed files
with
2 additions
and
165 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 was deleted.
Oops, something went wrong.
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,72 +1,6 @@ | ||
import { PrismaClient, Prisma } from '@prisma/client'; | ||
import config from '../config'; | ||
import gcm from '../helpers/gcmUtil'; | ||
|
||
const prisma = new PrismaClient(); | ||
|
||
// Prisma middleware to encrypt and decrypt data on fly | ||
prisma.$use(async (params, next) => { | ||
if (params.model !== 'connections') { | ||
return next(params); | ||
} | ||
|
||
const isReadOperation = ['findFirst', 'findMany', 'delete'].includes(params.action); | ||
const isWriteOperation = ['update', 'upsert'].includes(params.action); | ||
|
||
if (isReadOperation) { | ||
return handleReadOperation(params, next); | ||
} else if (isWriteOperation) { | ||
return handleWriteOperation(params, next); | ||
} | ||
return next(params); | ||
}); | ||
|
||
async function handleReadOperation( | ||
params: Prisma.MiddlewareParams, | ||
next: (params: Prisma.MiddlewareParams) => Promise<any> | ||
): Promise<any> { | ||
try { | ||
const connections = await next(params); | ||
if (!connections) return connections; | ||
if (Array.isArray(connections)) { | ||
connections.forEach((connection) => { | ||
connection.tp_customer_id = gcm.decrypt(connection.tp_customer_id, config.AES_ENCRYPTION_SECRET); | ||
}); | ||
} else { | ||
connections.tp_customer_id = gcm.decrypt(connections.tp_customer_id, config.AES_ENCRYPTION_SECRET); | ||
} | ||
return connections; | ||
} catch (error: any) { | ||
throw new Error(error); | ||
} | ||
} | ||
|
||
async function handleWriteOperation( | ||
params: Prisma.MiddlewareParams, | ||
_: (params: Prisma.MiddlewareParams) => Promise<any> | ||
): Promise<any> { | ||
try { | ||
if (Array.isArray(params.args?.data)) { | ||
params.args?.data.forEach((connection: any) => { | ||
connection.tp_customer_id = gcm.encrypt(connection.tp_customer_id, config.AES_ENCRYPTION_SECRET); | ||
}); | ||
} else { | ||
if (params.action === 'upsert') { | ||
params.args.create.tp_customer_id = gcm.encrypt( | ||
params.args.create.tp_customer_id, | ||
config.AES_ENCRYPTION_SECRET | ||
); | ||
} else { | ||
params.args.data.tp_customer_id = gcm.encrypt( | ||
params.args.data.tp_customer_id, | ||
config.AES_ENCRYPTION_SECRET | ||
); | ||
} | ||
} | ||
} catch (error: any) { | ||
throw new Error(error); | ||
} | ||
} | ||
|
||
export default prisma; | ||
export { Prisma }; |
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 was deleted.
Oops, something went wrong.
a1b3d86
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
revert-client – ./
revert-client-git-main-revertdev.vercel.app
app.revert.dev
revert-client-revertdev.vercel.app