added get stat api
This commit is contained in:
parent
1f4ddfa10b
commit
62e13e673f
@ -31,11 +31,18 @@ export class FormController {
|
|||||||
return this.formService.findAll(query);
|
return this.formService.findAll(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Get('stats')
|
||||||
|
@ApiOperation({ summary: 'Get Stats' })
|
||||||
|
async getStats() {
|
||||||
|
return await this.formService.getStats();
|
||||||
|
}
|
||||||
|
|
||||||
@Get(':formId')
|
@Get(':formId')
|
||||||
@ApiOperation({ summary: 'Find a form' })
|
@ApiOperation({ summary: 'Find a form' })
|
||||||
async find(@Param('formId') formId: string) {
|
async find(@Param('formId') formId: string) {
|
||||||
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) {
|
||||||
|
|||||||
@ -93,6 +93,36 @@ export class FormService {
|
|||||||
return form;
|
return form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getStats() {
|
||||||
|
const [totalForms, totalFields, fieldTypeBreakdown, formStatusBreakdown] =
|
||||||
|
await Promise.all([
|
||||||
|
this.formModel.countDocuments(),
|
||||||
|
this.formModel.aggregate([
|
||||||
|
{ $project: { fieldCount: { $size: '$fields' } } },
|
||||||
|
{ $group: { _id: null, total: { $sum: '$fieldCount' } } },
|
||||||
|
]),
|
||||||
|
this.formModel.aggregate([
|
||||||
|
{ $unwind: '$fields' },
|
||||||
|
{ $group: { _id: '$fields.keyType', count: { $sum: 1 } } },
|
||||||
|
]),
|
||||||
|
this.formModel.aggregate([
|
||||||
|
{
|
||||||
|
$group: {
|
||||||
|
_id: {
|
||||||
|
$cond: {
|
||||||
|
if: { $ifNull: ['$deletedAt', false] },
|
||||||
|
then: 'deleted',
|
||||||
|
else: 'active',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
count: { $sum: 1 },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
return { totalForms, totalFields, fieldTypeBreakdown, formStatusBreakdown };
|
||||||
|
}
|
||||||
|
|
||||||
async findInterface(formId: string): Promise<string> {
|
async findInterface(formId: string): Promise<string> {
|
||||||
const form = await this.formModel
|
const form = await this.formModel
|
||||||
.findOne({ id: formId, deletedAt: null })
|
.findOne({ id: formId, deletedAt: null })
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user