feat(nestjs): migrate to NestJS

This commit is contained in:
Ahmed Bouhuolia
2025-04-07 11:51:24 +02:00
parent f068218a16
commit 55fcc908ef
3779 changed files with 631 additions and 195332 deletions

View File

@@ -0,0 +1,44 @@
import * as bcrypt from 'bcrypt';
import { BaseModel } from '@/models/Model';
export class SystemUser extends BaseModel {
public readonly firstName: string;
public readonly lastName: string;
public readonly email: string;
public password: string;
public readonly active: boolean;
public readonly tenantId: number;
public readonly verifyToken: string;
public readonly verified: boolean;
public readonly inviteAcceptedAt!: string;
static get tableName() {
return 'users';
}
/**
* Model modifiers.
*/
static get modifiers() {
return {
/**
* Filters the invite accepted users.
*/
inviteAccepted(query) {
query.whereNotNull('invite_accepted_at');
},
};
}
async hashPassword(): Promise<void> {
const salt = await bcrypt.genSalt();
if (!/^\$2[abxy]?\$\d+\$/.test(this.password)) {
this.password = await bcrypt.hash(this.password, salt);
}
}
async checkPassword(plainPassword: string): Promise<boolean> {
return await bcrypt.compare(plainPassword, this.password);
}
}