Skip to content

Commit 0b429e0

Browse files
committed
Implement deleteProjectById and update cache on collection creation
1 parent 5302fcd commit 0b429e0

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

backend/controllers/project.controller.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const { URL } = require('url');
1111
const { getConnection } = require("../utils/connection.manager");
1212
const { getCompiledModel } = require("../utils/injectModel")
1313
const { storageRegistry } = require("../utils/registry");
14-
const { deleteProjectByApiKeyCache, setProjectById, getProjectById } = require("../services/redisCaching");
14+
const { deleteProjectByApiKeyCache, setProjectById, getProjectById, deleteProjectById } = require("../services/redisCaching");
1515

1616

1717

@@ -194,6 +194,8 @@ module.exports.createCollection = async (req, res) => {
194194
project.collections.push({ name: collectionName, model: schema });
195195
await project.save();
196196

197+
await deleteProjectById(projectId);
198+
await setProjectById(projectId, project);
197199
// Safe Response
198200
const projectObj = project.toObject();
199201
delete projectObj.apiKey;

backend/services/redisCaching.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,20 @@ async function getProjectById(id) {
6464
}
6565

6666

67+
async function deleteProjectById(id) {
68+
try {
69+
await redis.del(`project:id:${id}`);
70+
} catch (err) {
71+
console.log(err);
72+
}
73+
}
74+
75+
6776
module.exports = {
6877
setProjectByApiKeyCache,
6978
getProjectByApiKeyCache,
7079
deleteProjectByApiKeyCache,
7180
setProjectById,
72-
getProjectById
81+
getProjectById,
82+
deleteProjectById
7383
};

0 commit comments

Comments
 (0)