mirror of
https://github.com/KevinMidboe/immich.git
synced 2025-10-29 17:40:28 +00:00
Add OpenAPI Specs and Response DTOs (#320)
* Added swagger bearer auth method authentication accordingly * Update Auth endpoint * Added additional api information for authentication * Added Swagger CLI pluggin * Added DTO for /user endpoint * Added /device-info reponse DTOs * Implement server version * Added DTOs for /server-info * Added DTOs for /assets * Added album to Swagger group * Added generated specs file * Add Client API generator for web * Remove incorrectly placed node_modules * Created class to handle access token * Remove password and hash when getting all user * PR feedback * Fixed video from CLI doesn't get metadata extracted * Fixed issue with TSConfig to work with generated openAPI * PR feedback * Remove console.log
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { BadRequestException, Injectable, Logger } from '@nestjs/common';
|
||||
import { BadRequestException, Injectable, Logger, NotFoundException } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
import { Repository } from 'typeorm';
|
||||
import { AuthUserDto } from '../../decorators/auth-user.decorator';
|
||||
import { CreateDeviceInfoDto } from './dto/create-device-info.dto';
|
||||
import { UpdateDeviceInfoDto } from './dto/update-device-info.dto';
|
||||
import { DeviceInfoEntity } from '@app/database/entities/device-info.entity';
|
||||
import { DeviceInfoResponseDto, mapDeviceInfoResponse } from './response-dto/create-device-info-response.dto';
|
||||
|
||||
@Injectable()
|
||||
export class DeviceInfoService {
|
||||
@@ -13,7 +14,7 @@ export class DeviceInfoService {
|
||||
private deviceRepository: Repository<DeviceInfoEntity>,
|
||||
) {}
|
||||
|
||||
async create(createDeviceInfoDto: CreateDeviceInfoDto, authUser: AuthUserDto) {
|
||||
async create(createDeviceInfoDto: CreateDeviceInfoDto, authUser: AuthUserDto): Promise<DeviceInfoResponseDto> {
|
||||
const res = await this.deviceRepository.findOne({
|
||||
where: {
|
||||
deviceId: createDeviceInfoDto.deviceId,
|
||||
@@ -23,7 +24,7 @@ export class DeviceInfoService {
|
||||
|
||||
if (res) {
|
||||
Logger.log('Device Info Exist', 'createDeviceInfo');
|
||||
return res;
|
||||
return mapDeviceInfoResponse(res);
|
||||
}
|
||||
|
||||
const deviceInfo = new DeviceInfoEntity();
|
||||
@@ -31,20 +32,18 @@ export class DeviceInfoService {
|
||||
deviceInfo.deviceType = createDeviceInfoDto.deviceType;
|
||||
deviceInfo.userId = authUser.id;
|
||||
|
||||
try {
|
||||
return await this.deviceRepository.save(deviceInfo);
|
||||
} catch (e) {
|
||||
Logger.error('Error creating new device info', 'createDeviceInfo');
|
||||
}
|
||||
const newDeviceInfo = await this.deviceRepository.save(deviceInfo);
|
||||
|
||||
return mapDeviceInfoResponse(newDeviceInfo);
|
||||
}
|
||||
|
||||
async update(userId: string, updateDeviceInfoDto: UpdateDeviceInfoDto) {
|
||||
async update(userId: string, updateDeviceInfoDto: UpdateDeviceInfoDto): Promise<DeviceInfoResponseDto> {
|
||||
const deviceInfo = await this.deviceRepository.findOne({
|
||||
where: { deviceId: updateDeviceInfoDto.deviceId, userId: userId },
|
||||
});
|
||||
|
||||
if (!deviceInfo) {
|
||||
throw new BadRequestException('Device Not Found');
|
||||
throw new NotFoundException('Device Not Found');
|
||||
}
|
||||
|
||||
const res = await this.deviceRepository.update(
|
||||
@@ -55,9 +54,15 @@ export class DeviceInfoService {
|
||||
);
|
||||
|
||||
if (res.affected == 1) {
|
||||
return await this.deviceRepository.findOne({
|
||||
const updatedDeviceInfo = await this.deviceRepository.findOne({
|
||||
where: { deviceId: updateDeviceInfoDto.deviceId, userId: userId },
|
||||
});
|
||||
|
||||
if (!updatedDeviceInfo) {
|
||||
throw new NotFoundException('Device Not Found');
|
||||
}
|
||||
|
||||
return mapDeviceInfoResponse(updatedDeviceInfo);
|
||||
} else {
|
||||
throw new BadRequestException('Bad Request');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user