feat: add GET/PUT clients endpoints to SettingsController
GET /api/settings/clients — list all Betriebe ordered by name PUT /api/settings/clients/:id — update AgrarmonitorBetriebId Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -376,13 +376,26 @@ export class SettingsController {
|
|||||||
async updateCorrespondentSetting(@Param('id') id: string, @Body() body: { agrarmonitorId: number | null }) {
|
async updateCorrespondentSetting(@Param('id') id: string, @Body() body: { agrarmonitorId: number | null }) {
|
||||||
const corrId = parseInt(id, 10);
|
const corrId = parseInt(id, 10);
|
||||||
let setting = await this.corrSettingRepo.findOneBy({ CorrespondentId: corrId });
|
let setting = await this.corrSettingRepo.findOneBy({ CorrespondentId: corrId });
|
||||||
|
|
||||||
if (!setting) {
|
if (!setting) {
|
||||||
setting = this.corrSettingRepo.create({ CorrespondentId: corrId, AgrarmonitorId: body.agrarmonitorId });
|
setting = this.corrSettingRepo.create({ CorrespondentId: corrId, AgrarmonitorId: body.agrarmonitorId });
|
||||||
} else {
|
} else {
|
||||||
setting.AgrarmonitorId = body.agrarmonitorId;
|
setting.AgrarmonitorId = body.agrarmonitorId;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.corrSettingRepo.save(setting);
|
return this.corrSettingRepo.save(setting);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// === Betriebe ===
|
||||||
|
@Get('clients')
|
||||||
|
async getClients() {
|
||||||
|
return this.clientRepo.find({ order: { Name: 'ASC' } });
|
||||||
|
}
|
||||||
|
|
||||||
|
@Put('clients/:id')
|
||||||
|
async updateClient(@Param('id') id: string, @Body() body: { AgrarmonitorBetriebId: number | null }) {
|
||||||
|
const clientId = parseInt(id, 10);
|
||||||
|
await this.clientRepo.update(clientId, { AgrarmonitorBetriebId: body.AgrarmonitorBetriebId ?? null });
|
||||||
|
return this.clientRepo.findOneByOrFail({ Id: clientId });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user