class-validator
에 빈 공백 제거해주는 기능이 없음
trim
을 이용해 해결 하려 했지만
맨 왼쪽, 맨 오른쪽 문자열 공백만 제거 해주기 때문에
원하는 기능과 다름
/\s/
문자열에 빈 공백
이 있는 경우export function IsNotBlank(
property: string,
validationOptions?: ValidationOptions
) {
// eslint-disable-next-line @typescript-eslint/ban-types
return (object: Object, propertyName: string) => {
const isSpaceRegex = /\s/;
registerDecorator({
name: "isNotBlank",
target: object.constructor,
propertyName,
constraints: [property],
options: validationOptions,
validator: {
validate(value: any) {
return typeof value === "string" && !value.match(isSpaceRegex);
},
defaultMessage() {
return `Remove the space from the string.`;
},
},
});
};
}
로거에 넘겨줄 body와 다음 미들웨어의 body가 분리되지 않은 문제
예를들어
password
값을 필터링 했는데 다음 미들웨어에도 필터링된 상태
전개연산자로 deep copy
해서filterdBody
생성 후 logger에 넘겨줘서 해결
export const loggingReq = () => {
...
const filteredBody = { ...body };
Object.keys(body).forEach((k) => {
if (k.toLocaleLowerCase().indexOf("password") > -1) {
filteredBody.password = "FILTERED";
}
if (k.toLocaleLowerCase().indexOf("passwordConfirm") > -1) {
filteredBody.passwordconfirm = "FILTERED";
}
});
logger.info(`Parameters : ${JSON.stringify(filteredBody)}`);
}