removed isDeleted field from schema and updated related services
This commit is contained in:
parent
b2f181122e
commit
c9fa1a59d1
@ -4,7 +4,6 @@ import { InjectModel } from '@nestjs/mongoose';
|
|||||||
import { Form, FormDocument, Status } from './schemas/form.schema';
|
import { Form, FormDocument, Status } from './schemas/form.schema';
|
||||||
import { Model } from 'mongoose';
|
import { Model } from 'mongoose';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import { CreateFieldDto } from './dto/create-field.dto';
|
|
||||||
import { UpdateFieldDto } from './dto/update-field.dto';
|
import { UpdateFieldDto } from './dto/update-field.dto';
|
||||||
import { CreateUpdateDto } from './dto/create-update.dto';
|
import { CreateUpdateDto } from './dto/create-update.dto';
|
||||||
|
|
||||||
@ -38,11 +37,11 @@ export class FormService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async findAll(): Promise<Form[]> {
|
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> {
|
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`);
|
if (!form) throw new NotFoundException(`Form ${formId} not found`);
|
||||||
return form;
|
return form;
|
||||||
}
|
}
|
||||||
@ -82,10 +81,9 @@ export class FormService {
|
|||||||
|
|
||||||
async softDelete(FormId: string): Promise<Form> {
|
async softDelete(FormId: string): Promise<Form> {
|
||||||
const form = await this.formModel.findOneAndUpdate(
|
const form = await this.formModel.findOneAndUpdate(
|
||||||
{ id: FormId, isDeleted: false }, // prevent double deletion
|
{ id: FormId, deletedAt:null }, // prevent double deletion
|
||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
isDeleted: true,
|
|
||||||
deletedAt: new Date(),
|
deletedAt: new Date(),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -98,10 +96,9 @@ export class FormService {
|
|||||||
|
|
||||||
async restore(FormId: string): Promise<Form> {
|
async restore(FormId: string): Promise<Form> {
|
||||||
const form = await this.formModel.findOneAndUpdate(
|
const form = await this.formModel.findOneAndUpdate(
|
||||||
{ id: FormId, isDeleted: true },
|
{ id: FormId, deletedAt:{$ne:null} }, // only restore if actually deleted
|
||||||
{
|
{
|
||||||
$set: {
|
$set: {
|
||||||
isDeleted: false,
|
|
||||||
deletedAt: null,
|
deletedAt: null,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
@ -26,9 +26,6 @@ export class Form {
|
|||||||
})
|
})
|
||||||
status!: Status;
|
status!: Status;
|
||||||
|
|
||||||
@Prop({ default: false })
|
|
||||||
isDeleted?: boolean;
|
|
||||||
|
|
||||||
@Prop({ type: Date, default: null })
|
@Prop({ type: Date, default: null })
|
||||||
deletedAt?: Date;
|
deletedAt?: Date;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user