Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | 1x 1x 1x 1x 47x 47x 47x 47x 47x | import {property} from '@loopback/repository';
import {Type, Expose, Transform} from 'class-transformer';
import _ from 'lodash';
/**
* Custom decorator to handle User transformation
* @param exposeName - The name to expose in the response
* @param groups - Optional class-transformer groups
*/
export function UserTransform(exposeName: string, groups: string[] = []) {
return function (target: any, key: string) {
// Apply LoopBack's @property decorator
property({
type: 'object',
jsonSchema: {nullable: true},
})(target, key);
// Apply class-transformer's Type, Transform, and Expose decorators
Type(() => Object)(target, key);
Transform(({value}) => _.pick(value, ['name', 'id']))(target, key);
Expose({name: exposeName, groups})(target, key);
};
}
|