|
@@ -8,7 +8,7 @@ import {
|
|
|
InternalServerErrorException,
|
|
InternalServerErrorException,
|
|
|
UnauthorizedException
|
|
UnauthorizedException
|
|
|
} from '@nestjs/common'
|
|
} from '@nestjs/common'
|
|
|
-import { Repository, UpdateResult } from 'typeorm'
|
|
|
|
|
|
|
+import { And, LessThan, LessThanOrEqual, MoreThan, MoreThanOrEqual, Repository, UpdateResult } from 'typeorm'
|
|
|
import { InjectRepository } from '@nestjs/typeorm'
|
|
import { InjectRepository } from '@nestjs/typeorm'
|
|
|
import { Users } from './entities/users.entity'
|
|
import { Users } from './entities/users.entity'
|
|
|
import { IUsers } from './interfaces/users.interface'
|
|
import { IUsers } from './interfaces/users.interface'
|
|
@@ -21,6 +21,7 @@ import * as randomstring from 'randomstring'
|
|
|
import { paginate, Pagination } from 'nestjs-typeorm-paginate'
|
|
import { paginate, Pagination } from 'nestjs-typeorm-paginate'
|
|
|
import { Role } from 'src/model/role.enum'
|
|
import { Role } from 'src/model/role.enum'
|
|
|
import { PageRequest } from '../common/dto/page-request'
|
|
import { PageRequest } from '../common/dto/page-request'
|
|
|
|
|
+import { endOfDay, startOfDay } from 'date-fns'
|
|
|
|
|
|
|
|
@Injectable()
|
|
@Injectable()
|
|
|
export class UsersService {
|
|
export class UsersService {
|
|
@@ -100,11 +101,11 @@ export class UsersService {
|
|
|
public async login(username: string, password: string): Promise<Users> {
|
|
public async login(username: string, password: string): Promise<Users> {
|
|
|
let user = await this.userRepository.findOneBy({ username })
|
|
let user = await this.userRepository.findOneBy({ username })
|
|
|
if (!user) {
|
|
if (!user) {
|
|
|
- throw new UnauthorizedException('Username and password doesn\'t match')
|
|
|
|
|
|
|
+ throw new UnauthorizedException("Username and password doesn't match")
|
|
|
}
|
|
}
|
|
|
const isMatch = await this.hashingService.compare(password, user.password)
|
|
const isMatch = await this.hashingService.compare(password, user.password)
|
|
|
if (!isMatch) {
|
|
if (!isMatch) {
|
|
|
- throw new UnauthorizedException('Username and password doesn\'t match')
|
|
|
|
|
|
|
+ throw new UnauthorizedException("Username and password doesn't match")
|
|
|
}
|
|
}
|
|
|
return user
|
|
return user
|
|
|
}
|
|
}
|
|
@@ -197,4 +198,12 @@ export class UsersService {
|
|
|
user.iat = iat || Math.floor(new Date().getTime() / 1000) - 1
|
|
user.iat = iat || Math.floor(new Date().getTime() / 1000) - 1
|
|
|
return await this.userRepository.save(user)
|
|
return await this.userRepository.save(user)
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public async hasInvite(userId: number) {
|
|
|
|
|
+ const user = await this.userRepository.findOneBy({
|
|
|
|
|
+ invitor: userId,
|
|
|
|
|
+ createdAt: And(MoreThanOrEqual(startOfDay(new Date())), LessThanOrEqual(endOfDay(new Date())))
|
|
|
|
|
+ })
|
|
|
|
|
+ return !!user
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|