mirror of
https://github.com/MrSedan/neuro-reply-website.git
synced 2026-01-14 20:49:42 +03:00
38 lines
1.2 KiB
TypeScript
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;
|
|
}
|
|
}
|
|
}
|