Compare commits
No commits in common. "62e13e673f6922cb2e401cf2013172a566119241" and "5f34171a4a5e1d79c4b21e4af9df24b86786136b" have entirely different histories.
62e13e673f
...
5f34171a4a
@ -30,7 +30,7 @@ export class CreateFieldDto {
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
|
|
||||||
@ApiPropertyOptional({ type: [String], example: ['Very Satisfied', 'Satisfied']})
|
@ApiPropertyOptional({ type: [String], example: ['Very Satisfied', 'Satisfied'] })
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@IsString({ each: true })
|
@IsString({ each: true })
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
|
|||||||
@ -31,18 +31,11 @@ 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) {
|
||||||
|
|||||||
@ -14,6 +14,7 @@ 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 { CreateFieldDto } from './dto/create-field.dto';
|
||||||
|
import { threadCpuUsage } from 'process';
|
||||||
|
|
||||||
// Reusable projections
|
// Reusable projections
|
||||||
const LIST_PROJECTION = {
|
const LIST_PROJECTION = {
|
||||||
@ -93,36 +94,6 @@ 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 })
|
||||||
|
|||||||
@ -2,6 +2,7 @@ import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
|
|||||||
import { Document } from 'mongoose';
|
import { Document } from 'mongoose';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
|
|
||||||
import { PARENT_TYPE_KEYS, INPUT_SUB_TYPE_KEYS } from '../types/field.type';
|
import { PARENT_TYPE_KEYS, INPUT_SUB_TYPE_KEYS } from '../types/field.type';
|
||||||
import type { ParentKeyType, InputSubType } from '../types/field.type';
|
import type { ParentKeyType, InputSubType } from '../types/field.type';
|
||||||
|
|
||||||
@ -9,13 +10,13 @@ export type FieldDocument = Field & Document;
|
|||||||
|
|
||||||
@Schema({ timestamps: true })
|
@Schema({ timestamps: true })
|
||||||
export class Field {
|
export class Field {
|
||||||
@Prop({ required: true, unique: true, default: () => uuidv4() })
|
@Prop({ required: true, unique:true, default:()=>uuidv4()})
|
||||||
id!: string;
|
id!: string;
|
||||||
|
|
||||||
@Prop({ required: true, enum: PARENT_TYPE_KEYS })
|
@Prop({ required: true, enum: PARENT_TYPE_KEYS })
|
||||||
keyType!: ParentKeyType;
|
keyType!: ParentKeyType;
|
||||||
|
|
||||||
@Prop({ required: false, enum: INPUT_SUB_TYPE_KEYS })
|
@Prop({ required: false, enum: INPUT_SUB_TYPE_KEYS })
|
||||||
keySubType?: InputSubType;
|
keySubType?: InputSubType;
|
||||||
|
|
||||||
@Prop({ required: true })
|
@Prop({ required: true })
|
||||||
@ -27,11 +28,11 @@ export class Field {
|
|||||||
@Prop({ required: false })
|
@Prop({ required: false })
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
|
|
||||||
@Prop({ required: false, default: undefined })
|
@Prop({ required: false })
|
||||||
options?: string[];
|
options?: string[];
|
||||||
|
|
||||||
@Prop({ required: true, default: false })
|
@Prop({ required: true, default: false })
|
||||||
required!: boolean;
|
required!: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const FieldSchema = SchemaFactory.createForClass(Field);
|
export const FieldSchema = SchemaFactory.createForClass(Field);
|
||||||
Loading…
x
Reference in New Issue
Block a user