Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
crudOptions: Partial,
req: any,
): { filter?: any; or?: any } {
let auth: any = {};
/* istanbul ignore else */
if (crudOptions.auth) {
const userOrRequest = crudOptions.auth.property
? req[crudOptions.auth.property]
: req;
if (isFunction(crudOptions.auth.or)) {
auth.or = crudOptions.auth.or(userOrRequest);
}
if (isFunction(crudOptions.auth.filter) && !auth.or) {
auth.filter =
crudOptions.auth.filter(userOrRequest) || /* istanbul ignore next */ {};
}
if (isFunction(crudOptions.auth.persist)) {
parser.setAuthPersist(crudOptions.auth.persist(userOrRequest));
}
}
return auth;
}
}
getAuth(
parser: RequestQueryParser,
crudOptions: Partial,
req: any,
): { filter?: any; or?: any } {
let auth: any = {};
/* istanbul ignore else */
if (crudOptions.auth) {
const userOrRequest = crudOptions.auth.property
? req[crudOptions.auth.property]
: req;
if (isFunction(crudOptions.auth.or)) {
auth.or = crudOptions.auth.or(userOrRequest);
}
if (isFunction(crudOptions.auth.filter) && !auth.or) {
auth.filter =
crudOptions.auth.filter(userOrRequest) || /* istanbul ignore next */ {};
}
if (isFunction(crudOptions.auth.persist)) {
parser.setAuthPersist(crudOptions.auth.persist(userOrRequest));
}
}
return auth;
}
}
/* istanbul ignore else */
if (crudOptions.auth) {
const userOrRequest = crudOptions.auth.property
? req[crudOptions.auth.property]
: req;
if (isFunction(crudOptions.auth.or)) {
auth.or = crudOptions.auth.or(userOrRequest);
}
if (isFunction(crudOptions.auth.filter) && !auth.or) {
auth.filter =
crudOptions.auth.filter(userOrRequest) || /* istanbul ignore next */ {};
}
if (isFunction(crudOptions.auth.persist)) {
parser.setAuthPersist(crudOptions.auth.persist(userOrRequest));
}
}
return auth;
}
}
private setResponseModels() {
const modelType = isFunction(this.modelType)
? this.modelType
: SerializeHelper.createGetOneResponseDto(this.modelName);
this.swaggerModels.get = isFunction(this.options.serialize.get)
? this.options.serialize.get
: modelType;
this.swaggerModels.getMany =
this.options.serialize.getMany ||
SerializeHelper.createGetManyDto(this.swaggerModels.get, this.modelName);
this.swaggerModels.create = isFunction(this.options.serialize.create)
? this.options.serialize.create
: modelType;
this.swaggerModels.update = isFunction(this.options.serialize.update)
? this.options.serialize.update
: modelType;
this.swaggerModels.replace = isFunction(this.options.serialize.replace)
? this.options.serialize.replace
: modelType;
this.swaggerModels.delete = isFunction(this.options.serialize.delete)
? this.options.serialize.delete
: modelType;
Swagger.setExtraModels(this.swaggerModels);
}
private setResponseModels() {
const modelType = isFunction(this.modelType)
? this.modelType
: SerializeHelper.createGetOneResponseDto(this.modelName);
this.swaggerModels.get = isFunction(this.options.serialize.get)
? this.options.serialize.get
: modelType;
this.swaggerModels.getMany =
this.options.serialize.getMany ||
SerializeHelper.createGetManyDto(this.swaggerModels.get, this.modelName);
this.swaggerModels.create = isFunction(this.options.serialize.create)
? this.options.serialize.create
: modelType;
this.swaggerModels.update = isFunction(this.options.serialize.update)
? this.options.serialize.update
: modelType;
this.swaggerModels.replace = isFunction(this.options.serialize.replace)
? this.options.serialize.replace
protected transform(dto: any, data: any) {
if (!isObject(data) || isFalse(dto)) {
return data;
}
if (!isFunction(dto)) {
return data.constructor !== Object ? classToPlain(data) : data;
}
return data instanceof dto
? classToPlain(data)
: classToPlain(classToPlainFromExist(data, new dto()));
}
const modelType = isFunction(this.modelType)
? this.modelType
: SerializeHelper.createGetOneResponseDto(this.modelName);
this.swaggerModels.get = isFunction(this.options.serialize.get)
? this.options.serialize.get
: modelType;
this.swaggerModels.getMany =
this.options.serialize.getMany ||
SerializeHelper.createGetManyDto(this.swaggerModels.get, this.modelName);
this.swaggerModels.create = isFunction(this.options.serialize.create)
? this.options.serialize.create
: modelType;
this.swaggerModels.update = isFunction(this.options.serialize.update)
? this.options.serialize.update
: modelType;
this.swaggerModels.replace = isFunction(this.options.serialize.replace)
? this.options.serialize.replace
: modelType;
this.swaggerModels.delete = isFunction(this.options.serialize.delete)
? this.options.serialize.delete
: modelType;
Swagger.setExtraModels(this.swaggerModels);
}
private setResponseModels() {
const modelType = isFunction(this.modelType)
? this.modelType
: SerializeHelper.createGetOneResponseDto(this.modelName);
this.swaggerModels.get = isFunction(this.options.serialize.get)
? this.options.serialize.get
: modelType;
this.swaggerModels.getMany =
this.options.serialize.getMany ||
SerializeHelper.createGetManyDto(this.swaggerModels.get, this.modelName);
this.swaggerModels.create = isFunction(this.options.serialize.create)
? this.options.serialize.create
: modelType;
this.swaggerModels.update = isFunction(this.options.serialize.update)
? this.options.serialize.update
: modelType;
this.swaggerModels.replace = isFunction(this.options.serialize.replace)
? this.options.serialize.replace
: modelType;
this.swaggerModels.delete = isFunction(this.options.serialize.delete)
? this.options.serialize.delete
: modelType;
Swagger.setExtraModels(this.swaggerModels);
}