18 lines
536 B
TypeScript
18 lines
536 B
TypeScript
import { Injectable } from '@nestjs/common';
|
|
import { ApiError } from '../common/filters/api-error';
|
|
import { User } from '../common/store/domain';
|
|
import { StoreService } from '../common/store/store.service';
|
|
|
|
@Injectable()
|
|
export class UsersService {
|
|
constructor(private readonly store: StoreService) {}
|
|
|
|
register(username: string, displayName: string): User {
|
|
const user = this.store.createUser(username, displayName.trim());
|
|
if (!user) {
|
|
throw new ApiError('conflict', 'username is already taken');
|
|
}
|
|
return user;
|
|
}
|
|
}
|