Files
neuro-reply-website/backend/src/modules/admin/admin.service.ts
2023-11-20 21:52:00 +03:00

38 lines
1.2 KiB
TypeScript

import { Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Admin } from 'libs/database/admin.entity';
import { Repository } from 'typeorm';
@Injectable()
export class AdminService {
private readonly logger: Logger = new Logger(AdminService.name);
constructor(@InjectRepository(Admin) private adminRepository: Repository<Admin>) {}
async getAdmins() {
try {
this.logger.debug(`[admin.getAdmins]`);
const admins = await this.adminRepository.find();
return admins;
} catch (error) {
this.logger.log(`[getAdmin] ${JSON.stringify({ error })}`);
return [];
}
}
async checkIsAdmin(id: string) {
try {
this.logger.debug(`[admin.checkIsAdmin]`);
const admins = await this.adminRepository.findOne({
relations: { user: true },
where: { user: { id: id } },
});
if (!admins) {
return false;
}
return true;
} catch (error) {
this.logger.debug(`[checkIsAdmin] ${JSON.stringify({ error })}`);
return false;
}
}
}