add field to form api added
This commit is contained in:
parent
4c1ecafa77
commit
5f34171a4a
@ -13,15 +13,16 @@ import { ApiOperation } from '@nestjs/swagger';
|
|||||||
import { UpdateFieldDto } from './dto/update-field.dto';
|
import { UpdateFieldDto } from './dto/update-field.dto';
|
||||||
import { QueryFormDto } from './dto/query-form.dto';
|
import { QueryFormDto } from './dto/query-form.dto';
|
||||||
import { CreateFormDto } from './dto/create-form.dto';
|
import { CreateFormDto } from './dto/create-form.dto';
|
||||||
|
import { CreateFieldDto } from './dto/create-field.dto';
|
||||||
|
|
||||||
@Controller('form')
|
@Controller('form')
|
||||||
export class FormController {
|
export class FormController {
|
||||||
constructor(private readonly formService: FormService) {}
|
constructor(private readonly formService: FormService) {}
|
||||||
|
|
||||||
@Post('create-form')
|
@Post('create-form')
|
||||||
@ApiOperation({ summary: 'Create a Form'})
|
@ApiOperation({ summary: 'Create a Form' })
|
||||||
async createOne(@Body() createFormDto:CreateFormDto){
|
async createOne(@Body() createFormDto: CreateFormDto) {
|
||||||
return await this.formService.createForm(createFormDto)
|
return await this.formService.createForm(createFormDto);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
@ -36,11 +37,20 @@ export class FormController {
|
|||||||
return await this.formService.find(formId);
|
return await this.formService.find(formId);
|
||||||
}
|
}
|
||||||
@Get(':formId/interface')
|
@Get(':formId/interface')
|
||||||
@ApiOperation({summary:'Get interface for the form provided by llm'})
|
@ApiOperation({ summary: 'Get interface for the form provided by llm' })
|
||||||
async getInterface(@Param('formId') formId:string){
|
async getInterface(@Param('formId') formId: string) {
|
||||||
return await this.formService.findInterface(formId);
|
return await this.formService.findInterface(formId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Patch(':formId/field')
|
||||||
|
@ApiOperation({ summary: 'Add a field to a form' })
|
||||||
|
async addField(
|
||||||
|
@Param('formId') formId: string,
|
||||||
|
@Body() createFieldDto: CreateFieldDto,
|
||||||
|
) {
|
||||||
|
return await this.formService.addField(formId, createFieldDto);
|
||||||
|
}
|
||||||
|
|
||||||
@Patch(':id/fields/:fieldId')
|
@Patch(':id/fields/:fieldId')
|
||||||
@ApiOperation({ summary: 'update a field in a form' })
|
@ApiOperation({ summary: 'update a field in a form' })
|
||||||
async updateField(
|
async updateField(
|
||||||
|
|||||||
@ -13,6 +13,8 @@ import { FormQueryBuilder } from './helpers/form-query.builder';
|
|||||||
import { PaginatedResponse } from 'src/interfaces/paginated-response.interface';
|
import { PaginatedResponse } from 'src/interfaces/paginated-response.interface';
|
||||||
import { LlmService } from 'src/common/services/llm.service';
|
import { LlmService } from 'src/common/services/llm.service';
|
||||||
import { CreateFormDto } from './dto/create-form.dto';
|
import { CreateFormDto } from './dto/create-form.dto';
|
||||||
|
import { CreateFieldDto } from './dto/create-field.dto';
|
||||||
|
import { threadCpuUsage } from 'process';
|
||||||
|
|
||||||
// Reusable projections
|
// Reusable projections
|
||||||
const LIST_PROJECTION = {
|
const LIST_PROJECTION = {
|
||||||
@ -40,6 +42,16 @@ export class FormService {
|
|||||||
return form;
|
return form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async addField(formId: string, fieldDto: CreateFieldDto): Promise<Form> {
|
||||||
|
const updatedForm = await this.formModel.findOneAndUpdate(
|
||||||
|
{ id: formId },
|
||||||
|
{ $push: { fields: fieldDto } },
|
||||||
|
{ returnDocument: 'after' }, //as {new:true} will be deprecated
|
||||||
|
);
|
||||||
|
if (!updatedForm) throw new NotFoundException(`Form ${formId} not found`);
|
||||||
|
return updatedForm;
|
||||||
|
}
|
||||||
|
|
||||||
async findAll(query: QueryFormDto): Promise<PaginatedResponse<Form>> {
|
async findAll(query: QueryFormDto): Promise<PaginatedResponse<Form>> {
|
||||||
const filter = FormQueryBuilder.buildFilter(query);
|
const filter = FormQueryBuilder.buildFilter(query);
|
||||||
const sort = FormQueryBuilder.buildSort(query);
|
const sort = FormQueryBuilder.buildSort(query);
|
||||||
@ -113,7 +125,7 @@ export class FormService {
|
|||||||
{ id: formId },
|
{ id: formId },
|
||||||
{ $set: setPayload },
|
{ $set: setPayload },
|
||||||
{
|
{
|
||||||
new: true,
|
returnDocument: 'after',
|
||||||
arrayFilters: [{ 'elem.id': fieldId }],
|
arrayFilters: [{ 'elem.id': fieldId }],
|
||||||
projection: DETAIL_PROJECTION,
|
projection: DETAIL_PROJECTION,
|
||||||
},
|
},
|
||||||
@ -126,7 +138,7 @@ export class FormService {
|
|||||||
const form = await this.formModel.findOneAndUpdate(
|
const form = await this.formModel.findOneAndUpdate(
|
||||||
{ id: formId },
|
{ id: formId },
|
||||||
{ $pull: { fields: { id: fieldId } } },
|
{ $pull: { fields: { id: fieldId } } },
|
||||||
{ new: true, projection: DETAIL_PROJECTION },
|
{ returnDocument: 'after', projection: DETAIL_PROJECTION },
|
||||||
);
|
);
|
||||||
if (!form) throw new NotFoundException(`Form ${formId} not found`);
|
if (!form) throw new NotFoundException(`Form ${formId} not found`);
|
||||||
return form;
|
return form;
|
||||||
@ -140,7 +152,7 @@ export class FormService {
|
|||||||
deletedAt: new Date(),
|
deletedAt: new Date(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ new: true, projection: DETAIL_PROJECTION },
|
{ returnDocument: 'after', projection: DETAIL_PROJECTION },
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!form) throw new NotFoundException(`Form ${FormId} not found`);
|
if (!form) throw new NotFoundException(`Form ${FormId} not found`);
|
||||||
@ -155,7 +167,7 @@ export class FormService {
|
|||||||
deletedAt: null,
|
deletedAt: null,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{ new: true, projection: DETAIL_PROJECTION },
|
{ returnDocument: 'after', projection: DETAIL_PROJECTION },
|
||||||
);
|
);
|
||||||
if (!form) throw new NotFoundException(`Form ${FormId} not found`);
|
if (!form) throw new NotFoundException(`Form ${FormId} not found`);
|
||||||
return form;
|
return form;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user