Updated the expiry date to be based on the expiry date
This commit is contained in:
@@ -6,9 +6,11 @@ import { deleteEntity, getEntity, getEntityWithRoles } from "@/utils/entities.be
|
||||
import client from "@/lib/mongodb";
|
||||
import { Entity } from "@/interfaces/entity";
|
||||
import { doesEntityAllow } from "@/utils/permissions";
|
||||
import { getUser } from "@/utils/users.be";
|
||||
import { getEntityUsers, getUser } from "@/utils/users.be";
|
||||
import { requestUser } from "@/utils/api";
|
||||
import { isAdmin } from "@/utils/users";
|
||||
import { filterBy, mapBy } from "@/utils";
|
||||
import { User } from "@/interfaces/user";
|
||||
|
||||
const db = client.db(process.env.MONGODB_DB);
|
||||
|
||||
@@ -66,5 +68,22 @@ async function patch(req: NextApiRequest, res: NextApiResponse) {
|
||||
return res.status(200).json({ ok: entity.acknowledged });
|
||||
}
|
||||
|
||||
if (req.body.expiryDate !== undefined) {
|
||||
const entity = await getEntity(id)
|
||||
const result = await db.collection<Entity>("entities").updateOne({ id }, { $set: { expiryDate: req.body.expiryDate } });
|
||||
|
||||
const users = await getEntityUsers(id, 0, {
|
||||
subscriptionExpirationDate: entity?.expiryDate,
|
||||
$and: [
|
||||
{ type: { $ne: "admin" } },
|
||||
{ type: { $ne: "developer" } },
|
||||
]
|
||||
})
|
||||
|
||||
await db.collection<User>("users").updateMany({ id: { $in: mapBy(users, 'id') } }, { $set: { subscriptionExpirationDate: req.body.expiryDate } })
|
||||
|
||||
return res.status(200).json({ ok: result.acknowledged });
|
||||
}
|
||||
|
||||
return res.status(200).json({ ok: true });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user