Skip to content

Commit 28c76e8

Browse files
committed
fix: Remove unused stuff and update service references since i had to rename the package
1 parent e662260 commit 28c76e8

File tree

2 files changed

+2
-42
lines changed

2 files changed

+2
-42
lines changed

middlewares/versioning/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
module.exports = strapi => ({
22
initialize () {
33
const versioningPlugin = strapi.plugins.versioning
4-
const versioningService = versioningPlugin.services.versioning
4+
const versioningService = versioningPlugin.services['versioning-mongo']
55
const versionModel = versioningPlugin.models.version
6-
const contentManagerService = strapi.plugins['content-manager'].services['content-types']
76

87
const newVersionMethods = ['PUT', 'POST']
98
const shouldCreateVersion = (ctx, model) =>
@@ -18,8 +17,6 @@ module.exports = strapi => ({
1817
const strapiModel = versioningService.getStrapiModel(model)
1918
if (id && shouldCreateVersion(ctx, strapiModel)) {
2019
const entry = await versioningService.getEntryVersion(strapiModel, id)
21-
const configuration = await contentManagerService.findContentType(strapiModel.uid)
22-
console.log(configuration)
2320
const versionEntry = versioningService.getVersionEntry(strapiModel, entry)
2421
await versionModel.create(versionEntry)
2522
}

services/versioning.js

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { cloneDeep, isEmpty } = require('lodash')
1+
const { cloneDeep } = require('lodash')
22

33
const sanitizeContent = (entry) => {
44
const removeProperties = ['id', '_id', '__v', '__component', 'published_at', 'created_by', 'updated_by']
@@ -9,22 +9,6 @@ const sanitizeContent = (entry) => {
99
return content
1010
}
1111

12-
const stringifyObjectIds = (obj) => {
13-
const keysToRemove = ['_id', '__v']
14-
if (Array.isArray(obj)) {
15-
obj = obj.map(stringifyObjectIds)
16-
} else if (typeof obj === 'object' && !isEmpty(obj)) {
17-
for (const key in obj) {
18-
if (keysToRemove.includes(key)) {
19-
delete obj[key]
20-
} else {
21-
obj[key] = stringifyObjectIds(obj[key])
22-
}
23-
}
24-
}
25-
return obj
26-
}
27-
2812
module.exports = {
2913
getModelFromCtx: (ctx) => ctx?.params?.model,
3014

@@ -36,27 +20,6 @@ module.exports = {
3620
return strapi.query(model.uid).findOne({ id })
3721
},
3822

39-
normalizeVersion: async (id) => {
40-
const versioningPlugin = strapi.plugins.versioning
41-
const versionModel = versioningPlugin.models.version
42-
const contentManagerService = strapi.plugins['content-manager'].services['content-types']
43-
44-
let version = await versionModel.findById(id).lean()
45-
const { content, collectionId } = version
46-
const configuration = await contentManagerService.findContentType(collectionId)
47-
for (const attribute of Object.keys(configuration.allAttributes ?? {})) {
48-
const val = content[attribute]
49-
if (!val) {
50-
content[attribute] = null
51-
}
52-
}
53-
version = stringifyObjectIds(version)
54-
55-
console.log(JSON.stringify(version, null, 2))
56-
delete version.content.Link.id
57-
return version
58-
},
59-
6023
getVersionEntry: (model, entry) => {
6124
const version = {
6225
collectionName: model.collectionName,

0 commit comments

Comments
 (0)