mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
refactor(server): user create logic (#13728)
This commit is contained in:
parent
fb995816a1
commit
43d18ccc36
4 changed files with 47 additions and 62 deletions
|
|
@ -15,7 +15,6 @@ import { JobName } from 'src/interfaces/job.interface';
|
|||
import { UserFindOptions } from 'src/interfaces/user.interface';
|
||||
import { BaseService } from 'src/services/base.service';
|
||||
import { getPreferences, getPreferencesPartial, mergePreferences } from 'src/utils/preferences';
|
||||
import { createUser } from 'src/utils/user';
|
||||
|
||||
@Injectable()
|
||||
export class UserAdminService extends BaseService {
|
||||
|
|
@ -25,17 +24,18 @@ export class UserAdminService extends BaseService {
|
|||
}
|
||||
|
||||
async create(dto: UserAdminCreateDto): Promise<UserAdminResponseDto> {
|
||||
const { notify, ...rest } = dto;
|
||||
const { notify, ...userDto } = dto;
|
||||
const config = await this.getConfig({ withCache: false });
|
||||
if (!config.oauth.enabled && !rest.password) {
|
||||
if (!config.oauth.enabled && !userDto.password) {
|
||||
throw new BadRequestException('password is required');
|
||||
}
|
||||
const user = await createUser({ userRepo: this.userRepository, cryptoRepo: this.cryptoRepository }, rest);
|
||||
|
||||
const user = await this.createUser(userDto);
|
||||
|
||||
await this.eventRepository.emit('user.signup', {
|
||||
notify: !!notify,
|
||||
id: user.id,
|
||||
tempPassword: user.shouldChangePassword ? rest.password : undefined,
|
||||
tempPassword: user.shouldChangePassword ? userDto.password : undefined,
|
||||
});
|
||||
|
||||
return mapUserAdmin(user);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue