Added regenerateKey to the projects.ts controller
This commit is contained in:
parent
d3b5ed8b3b
commit
265447f068
@ -1,6 +1,7 @@
|
||||
import { Project } from "@models/Project";
|
||||
import { encryptClearField } from "@utils/decryption";
|
||||
import { Types } from "mongoose";
|
||||
import crypto from "crypto";
|
||||
|
||||
export const createProject = async (name: string, userId?: string) => {
|
||||
const count = await Project.countDocuments({ creatorId: encryptClearField(userId || "") });
|
||||
@ -34,3 +35,13 @@ export const patchProject = async (id: string, config: {
|
||||
|
||||
await project.updateOne({ name: config.name, defaults: Object.assign(project.defaults, config.defaults) });
|
||||
};
|
||||
|
||||
export const regenerateKey = async (id: string) => {
|
||||
if (!Types.ObjectId.isValid(id))
|
||||
return { code: 3, message: "Invalid object id provided" };
|
||||
|
||||
const project = await Project.findById(id);
|
||||
if (project === null) return { code: 5009, message: "The provided project id does not exist" };
|
||||
|
||||
await project.updateOne({ validationKey: crypto.randomBytes(24).toString("hex") });
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user