removeRelation
lets add removeRelation
functions:
Example
const removeMostLovedCityValidator = () => {
return object({
set: object({
_id: objectIdValidation,
lovedCity: objectIdValidation,
}),
get: coreApp.schemas.selectStruct("user", 1),
});
};
const removeMostLovedCity: ActFn = async (body) => {
const { lovedCity, _id } = body.details.set;
return await users.removeRelation({
filters: { _id: new ObjectId(_id) },
projection: body.details.get,
relations: {
mostLovedCity: {
_ids: new ObjectId(lovedCity),
relatedRelations: {
lovedByUser: true,
},
},
},
});
};
coreApp.acts.setAct({
schema: "user",
actName: "removeMostLovedCity",
validator: removeMostLovedCityValidator(),
fn: removeMostLovedCity,
});
removeRelations
functions accept three inputs:
Return Of Example:
{
body: {
_id: 65a3d561b7f33fd5950b932e,
name: Erfan Gholami,
age: 22,
livedCities: [
{
_id: 65a3d560b7f33fd5950b931f,
name: Tehran,
population: 50,
abb: TH
},
{
_id: 65a3d560b7f33fd5950b9320,
name: Kerman,
population: 12,
abb: KM
}
],
country: {
_id: 65a3d55fb7f33fd5950b9312,
name: Iran,
population: 15000000,
abb: IRI
},
mostLovedCity: {}
},
success: true
}