Add validation to batch secret endpoint

This commit is contained in:
Tuan Dang
2023-02-17 01:12:13 +07:00
parent 65bec23292
commit 625c0785b5
2 changed files with 29 additions and 16 deletions
@@ -44,23 +44,15 @@ export const batchSecrets = async (req: Request, res: Response) => {
}= req.body;
// construct object containing all secrets
// listed across requests
const listedSecretsObj: {
[key: string]: {
version: number;
type: string;
}
} = (await Secret.find({
_id: {
$in: requests
.map((request) => request.secret._id)
.filter((secretId) => secretId !== undefined)
}
}).select('version type')).reduce((obj: any, secret: ISecret) => ({
} = req.secrets.reduce((obj: any, secret: ISecret) => ({
...obj,
[secret._id.toString()]: secret
}), {});
const createSecrets: BatchSecret[] = [];
const updateSecrets: BatchSecret[] = [];