Compare commits
No commits in common. "c9fa1a59d191313913f6e7883afd16663d2ef5be" and "99c88d2800e8e0a91be3ea33629f27934a033af5" have entirely different histories.
c9fa1a59d1
...
99c88d2800
@ -12,7 +12,6 @@ import { ApiOperation } from '@nestjs/swagger';
|
||||
import { UpdateFieldDto } from './dto/update-field.dto';
|
||||
import { CreateUpdateDto } from './dto/create-update.dto';
|
||||
|
||||
|
||||
@Controller('form')
|
||||
export class FormController {
|
||||
constructor(private readonly formService: FormService) {}
|
||||
@ -29,12 +28,6 @@ export class FormController {
|
||||
return await this.formService.findAll();
|
||||
}
|
||||
|
||||
@Get(':formId')
|
||||
@ApiOperation({ summary: 'Find a form' })
|
||||
async find(@Param('formId') formId: string) {
|
||||
return await this.formService.find(formId);
|
||||
}
|
||||
|
||||
@Patch(':id/fields/:fieldId')
|
||||
@ApiOperation({ summary: 'update a field in a form' })
|
||||
async updateField(
|
||||
@ -47,22 +40,7 @@ export class FormController {
|
||||
|
||||
@Delete(':id/fields/:fieldId')
|
||||
@ApiOperation({ summary: 'Delete a field' })
|
||||
async deleteField(
|
||||
@Param('id') id: string,
|
||||
@Param('fieldId') fieldId: string,
|
||||
) {
|
||||
return await this.formService.deleteField(id, fieldId);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ApiOperation({ summary: 'Soft delete a form' })
|
||||
async softDelete(@Param('id') id: string) {
|
||||
return await this.formService.softDelete(id);
|
||||
}
|
||||
|
||||
@Patch(':id/restore')
|
||||
@ApiOperation({ summary: 'Restore a soft deleted form' })
|
||||
restore(@Param('id') id: string) {
|
||||
return this.formService.restore(id);
|
||||
deleteField(@Param('id') id: string, @Param('fieldId') fieldId: string) {
|
||||
return this.formService.deleteField(id, fieldId);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
import { FormModule } from './form.module';
|
||||
import { Injectable, NotFoundException } from '@nestjs/common';
|
||||
import { InjectModel } from '@nestjs/mongoose';
|
||||
import { Form, FormDocument, Status } from './schemas/form.schema';
|
||||
import { Model } from 'mongoose';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { CreateFieldDto } from './dto/create-field.dto';
|
||||
import { UpdateFieldDto } from './dto/update-field.dto';
|
||||
import { CreateUpdateDto } from './dto/create-update.dto';
|
||||
|
||||
|
||||
@Injectable()
|
||||
export class FormService {
|
||||
constructor(@InjectModel(Form.name) private formModel: Model<FormDocument>) {}
|
||||
@ -37,11 +36,11 @@ export class FormService {
|
||||
}
|
||||
|
||||
async findAll(): Promise<Form[]> {
|
||||
return await this.formModel.find({deletedAt:null}).exec();
|
||||
return await this.formModel.find().exec();
|
||||
}
|
||||
|
||||
async find(formId: string): Promise<Form> {
|
||||
const form = await this.formModel.findOne({ id: formId, deletedAt:null }).exec();
|
||||
const form = await this.formModel.findOne({ id: formId }).exec();
|
||||
if (!form) throw new NotFoundException(`Form ${formId} not found`);
|
||||
return form;
|
||||
}
|
||||
@ -78,33 +77,4 @@ export class FormService {
|
||||
if (!form) throw new NotFoundException(`Form ${formId} not found`);
|
||||
return form;
|
||||
}
|
||||
|
||||
async softDelete(FormId: string): Promise<Form> {
|
||||
const form = await this.formModel.findOneAndUpdate(
|
||||
{ id: FormId, deletedAt:null }, // prevent double deletion
|
||||
{
|
||||
$set: {
|
||||
deletedAt: new Date(),
|
||||
},
|
||||
},
|
||||
{ new: true },
|
||||
);
|
||||
|
||||
if (!form) throw new NotFoundException(`Form ${FormId} not found`);
|
||||
return form;
|
||||
}
|
||||
|
||||
async restore(FormId: string): Promise<Form> {
|
||||
const form = await this.formModel.findOneAndUpdate(
|
||||
{ id: FormId, deletedAt:{$ne:null} }, // only restore if actually deleted
|
||||
{
|
||||
$set: {
|
||||
deletedAt: null,
|
||||
},
|
||||
},
|
||||
{ new: true },
|
||||
);
|
||||
if (!form) throw new NotFoundException(`Form ${FormId} not found`);
|
||||
return form;
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,9 +25,6 @@ export class Form {
|
||||
default: Status.DRAFT,
|
||||
})
|
||||
status!: Status;
|
||||
|
||||
@Prop({ type: Date, default: null })
|
||||
deletedAt?: Date;
|
||||
}
|
||||
|
||||
export const FormSchema = SchemaFactory.createForClass(Form);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user