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 25 26 27 28 29 30 31 32 33 34 35 36 37 | 1x 1x 1x 1x 1x 1x 331x 331x 331x 331x 331x 331x 331x 1x 1x 5x 1x | import {Getter, inject} from '@loopback/core'; import {BelongsToAccessor, DefaultCrudRepository, HasManyRepositoryFactory, repository} from '@loopback/repository'; import {MysqlDataSource} from '../datasources'; import {Roles, User, UserDetails, UserRelations} from '../models'; import {validateEmailExist} from '../services'; import {RolesRepository} from './roles.repository'; import {UserDetailsRepository} from './user-details.repository'; export class UserRepository extends DefaultCrudRepository< User, typeof User.prototype.UID, UserRelations > { public readonly role: BelongsToAccessor<Roles, typeof User.prototype.UID>; public readonly userDetails: HasManyRepositoryFactory<UserDetails, typeof User.prototype.UID>; constructor( @inject('datasources.mysql') dataSource: MysqlDataSource, @repository.getter('RolesRepository') protected rolesRepositoryGetter: Getter<RolesRepository>, @repository.getter('UserDetailsRepository') protected userDetailsRepositoryGetter: Getter<UserDetailsRepository>, ) { super(User, dataSource); this.userDetails = this.createHasManyRepositoryFactoryFor('userDetails', userDetailsRepositoryGetter,); this.registerInclusionResolver('userDetails', this.userDetails.inclusionResolver); this.role = this.createBelongsToAccessorFor('role', rolesRepositoryGetter,); this.registerInclusionResolver('role', this.role.inclusionResolver); } definePersistedModel(entityClass: typeof User) { const modelClass = super.definePersistedModel(entityClass); modelClass.observe('before save', async ctx => { validateEmailExist() }); return modelClass; } } |