feat(file-upload-settings): Add API endpoint and logic to retrieve settings by entity

This commit is contained in:
ghost2023
2026-06-03 11:52:05 +03:00
parent 36a8002163
commit 9e4e44ee6a
4 changed files with 20 additions and 0 deletions

View File

@@ -42,6 +42,12 @@ export class FileUploadSettingsController {
return this.service.getByCode(code); return this.service.getByCode(code);
} }
@Get("by-entity/:entity")
@ApiOperation({ summary: "Get all file upload settings for an entity type (customer, booking, etc.)" })
getByEntity(@Param("entity") entity: string) {
return this.service.getByEntity(entity);
}
@Post() @Post()
@ApiOperation({ summary: "Create a new file upload setting" }) @ApiOperation({ summary: "Create a new file upload setting" })
create(@Body() dto: CreateFileUploadSettingDto) { create(@Body() dto: CreateFileUploadSettingDto) {

View File

@@ -21,6 +21,15 @@ export class FileUploadSettingsRepository
super(repository); super(repository);
} }
/** Look up all settings for a given entity (e.g. "customer", "booking"). */
findByEntity(entity: string): Promise<FileUploadSetting[]> {
return this.repository.find({
where: { entity },
order: { label: "ASC" },
relations: { fields: true },
});
}
/** Look up a setting by its stable code. */ /** Look up a setting by its stable code. */
findByCode(code: string): Promise<FileUploadSetting | null> { findByCode(code: string): Promise<FileUploadSetting | null> {
return this.repository.findOne({ return this.repository.findOne({

View File

@@ -33,6 +33,10 @@ export class FileUploadSettingsService {
return setting; return setting;
} }
getByEntity(entity: string): Promise<FileUploadSetting[]> {
return this.repository.findByEntity(entity);
}
async getByCode(code: string): Promise<FileUploadSetting> { async getByCode(code: string): Promise<FileUploadSetting> {
const setting = await this.repository.findByCode(code); const setting = await this.repository.findByCode(code);
if (!setting) throw new NotFoundException(`Setting "${code}" not found`); if (!setting) throw new NotFoundException(`Setting "${code}" not found`);

View File

@@ -13,6 +13,7 @@ export interface IFileUploadSettingsRepository {
findAll(): Promise<FileUploadSetting[]>; findAll(): Promise<FileUploadSetting[]>;
findById(id: string): Promise<FileUploadSetting | null>; findById(id: string): Promise<FileUploadSetting | null>;
findByCode(code: string): Promise<FileUploadSetting | null>; findByCode(code: string): Promise<FileUploadSetting | null>;
findByEntity(entity: string): Promise<FileUploadSetting[]>;
create(data: Partial<FileUploadSetting>): Promise<FileUploadSetting>; create(data: Partial<FileUploadSetting>): Promise<FileUploadSetting>;
update( update(