59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
|
import { EntityNotFoundError, In, Not, Repository } from 'typeorm';
|
|
import { Roles } from './entities/roles.entity';
|
|
import { InjectRepository } from '@nestjs/typeorm';
|
|
|
|
@Injectable()
|
|
export class RoleService {
|
|
constructor(
|
|
@InjectRepository(Roles)
|
|
private rolesRepository: Repository<Roles>,
|
|
) {}
|
|
|
|
findAllRoles(page) {
|
|
return this.rolesRepository.findAndCount({
|
|
skip: page * 10,
|
|
take: 10,
|
|
order: {
|
|
version: 'DESC',
|
|
},
|
|
});
|
|
}
|
|
|
|
findAllRolesForCreateMember(page) {
|
|
return this.rolesRepository.findAndCount({
|
|
skip: page * 10,
|
|
take: 10,
|
|
where: {
|
|
id: Not(
|
|
In([
|
|
'3196cdf4-ae5f-4677-9bcd-98be35c72321',
|
|
'21dceea2-416e-4b55-b74c-12605e1f8d1b',
|
|
]),
|
|
),
|
|
},
|
|
order: {
|
|
version: 'DESC',
|
|
},
|
|
});
|
|
}
|
|
|
|
async findOne(id: string) {
|
|
try {
|
|
return await this.rolesRepository.findOneOrFail(id);
|
|
} catch (e) {
|
|
if (e instanceof EntityNotFoundError) {
|
|
throw new HttpException(
|
|
{
|
|
statusCode: HttpStatus.NOT_FOUND,
|
|
error: 'Data Role not found',
|
|
},
|
|
HttpStatus.NOT_FOUND,
|
|
);
|
|
} else {
|
|
throw e;
|
|
}
|
|
}
|
|
}
|
|
}
|