1- const { cloneDeep, isEmpty } = require ( 'lodash' )
1+ const { cloneDeep } = require ( 'lodash' )
22
33const 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-
2812module . 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