removed isDeleted field from schema and updated related services

This commit is contained in:
Suman991 2026-04-09 13:19:01 +05:30
parent b2f181122e
commit c9fa1a59d1
2 changed files with 4 additions and 10 deletions

View File

@ -4,7 +4,6 @@ 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';
@ -38,11 +37,11 @@ export class FormService {
}
async findAll(): Promise<Form[]> {
return await this.formModel.find({isDeleted:false}).exec();
return await this.formModel.find({deletedAt:null}).exec();
}
async find(formId: string): Promise<Form> {
const form = await this.formModel.findOne({ id: formId, isDeleted:false }).exec();
const form = await this.formModel.findOne({ id: formId, deletedAt:null }).exec();
if (!form) throw new NotFoundException(`Form ${formId} not found`);
return form;
}
@ -82,10 +81,9 @@ export class FormService {
async softDelete(FormId: string): Promise<Form> {
const form = await this.formModel.findOneAndUpdate(
{ id: FormId, isDeleted: false }, // prevent double deletion
{ id: FormId, deletedAt:null }, // prevent double deletion
{
$set: {
isDeleted: true,
deletedAt: new Date(),
},
},
@ -98,10 +96,9 @@ export class FormService {
async restore(FormId: string): Promise<Form> {
const form = await this.formModel.findOneAndUpdate(
{ id: FormId, isDeleted: true },
{ id: FormId, deletedAt:{$ne:null} }, // only restore if actually deleted
{
$set: {
isDeleted: false,
deletedAt: null,
},
},

View File

@ -26,9 +26,6 @@ export class Form {
})
status!: Status;
@Prop({ default: false })
isDeleted?: boolean;
@Prop({ type: Date, default: null })
deletedAt?: Date;
}