Relax signature preference validation for FirmaEC
This commit is contained in:
@@ -4,41 +4,32 @@ const ALLOWED_SIGNATURE_STYLES = ['classic', 'qr', 'professional', 'firmaec'];
|
||||
const ALLOWED_QR_POSITIONS = ['left', 'right'];
|
||||
const ALLOWED_QR_BACKGROUNDS = ['transparent', 'soft'];
|
||||
const ALLOWED_QR_BORDERS = ['none', 'line'];
|
||||
const LEGACY_SIGNATURE_STYLE_MAP = {
|
||||
image: 'qr',
|
||||
};
|
||||
|
||||
const getSignaturePreferences = async (userId) => {
|
||||
return usersRepository.getSignaturePreferences(userId);
|
||||
};
|
||||
|
||||
const updateSignaturePreferences = async (userId, { signatureStyle, qrPosition, qrBackground, qrBorder, signatureImageBase64 }) => {
|
||||
if (!ALLOWED_SIGNATURE_STYLES.includes(signatureStyle)) {
|
||||
const normalizedSignatureStyle = LEGACY_SIGNATURE_STYLE_MAP[String(signatureStyle || '').toLowerCase()] || signatureStyle;
|
||||
if (!ALLOWED_SIGNATURE_STYLES.includes(normalizedSignatureStyle)) {
|
||||
const error = new Error('Invalid signature style.');
|
||||
error.statusCode = 400;
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (!ALLOWED_QR_POSITIONS.includes(qrPosition)) {
|
||||
const error = new Error('Invalid QR position.');
|
||||
error.statusCode = 400;
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (!ALLOWED_QR_BACKGROUNDS.includes(qrBackground)) {
|
||||
const error = new Error('Invalid QR background.');
|
||||
error.statusCode = 400;
|
||||
throw error;
|
||||
}
|
||||
|
||||
if (!ALLOWED_QR_BORDERS.includes(qrBorder)) {
|
||||
const error = new Error('Invalid QR border.');
|
||||
error.statusCode = 400;
|
||||
throw error;
|
||||
}
|
||||
// Preferences should be resilient to stale clients or partially populated forms.
|
||||
const resolvedQrPosition = ALLOWED_QR_POSITIONS.includes(qrPosition) ? qrPosition : 'left';
|
||||
const resolvedQrBackground = ALLOWED_QR_BACKGROUNDS.includes(qrBackground) ? qrBackground : 'transparent';
|
||||
const resolvedQrBorder = ALLOWED_QR_BORDERS.includes(qrBorder) ? qrBorder : 'none';
|
||||
|
||||
return usersRepository.setSignaturePreferences(userId, {
|
||||
signatureStyle,
|
||||
qrPosition,
|
||||
qrBackground,
|
||||
qrBorder,
|
||||
signatureStyle: normalizedSignatureStyle,
|
||||
qrPosition: resolvedQrPosition,
|
||||
qrBackground: resolvedQrBackground,
|
||||
qrBorder: resolvedQrBorder,
|
||||
signatureImageBase64: signatureImageBase64 || null,
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user