Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (resData.payload.entity == null) return resData;
// @ts-ignore
const newEntity = visitor(resData.payload.entity);
const { $set, $docPath } = $bind();
// @ts-ignore
if (newEntity === resData.payload.entity) return resData;
// @ts-ignore
return update(resData, $set($docPath("payload", "entity"), newEntity));
}
case "login": {
if (resData.payload.user == null) return resData;
const newUser = visitor(resData.payload.user);
if (newUser === resData.payload.user) return resData;
const { $set, $docPath } = $bind();
return update(resData, $set($docPath("payload", "user"), newUser));
}
case "insertOne":
case "insertMulti":
case "updateById":
case "updateMulti":
case "delete":
case "logout": {
return resData;
}
default:
return resData;
}
}
export function encryptPasswordInRequestData(
reqData: GeneralUserEntityRequestData,
passwordPropName: DocumentPath,
encrypt: EncryptFunction
): GeneralUserEntityRequestData {
switch (reqData.method) {
case "insertOne":
case "insertAndGet": {
const { payload } = reqData;
const { value } = payload;
const password = getNestedValue(value, passwordPropName);
if (password) {
const { $set, $docPath } = $bind();
const valueWithEncryptedPass = update(
value,
// @ts-ignore password always exists
$set($docPath(passwordPropName), encrypt(password))
);
const { $set: $OtherSet, $docPath: $otherDocPath } = $bind<
typeof reqData
>();
return update(
reqData,
$OtherSet($otherDocPath("payload", "value"), valueWithEncryptedPass)
);
} else {
return reqData;
}
}