File tree Expand file tree Collapse file tree
plugins/data-import/server/content-types/datafile Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ module . exports = {
2+ async beforeCreate ( event ) {
3+ event . params . data . uid = await strapi . service ( 'plugin::content-manager.uid' )
4+ . generateUIDField ( {
5+ contentTypeUID : 'api::collection.collection' ,
6+ field : 'uid' ,
7+ data : event . params . data
8+ } ) ;
9+ } ,
10+ async beforeUpdate ( event ) {
11+ const { data, where } = event . params ;
12+
13+ const isPublishAction = 'publishedAt' in data ;
14+
15+ if ( ! isPublishAction ) {
16+ const entry = await strapi . entityService . findOne ( 'api::collection.collection' , where . id ) ;
17+
18+ if ( 'name' in data && data . name !== entry . name ) {
19+ event . params . data . uid = await strapi . service ( 'plugin::content-manager.uid' )
20+ . generateUIDField ( {
21+ contentTypeUID : 'api::collection.collection' ,
22+ field : 'uid' ,
23+ data : data
24+ } ) ;
25+ }
26+ }
27+ } ,
28+
29+ } ;
Original file line number Diff line number Diff line change 2828 "name" : {
2929 "type" : " string" ,
3030 "unique" : true
31+ },
32+ "uid" : {
33+ "type" : " uid" ,
34+ "targetField" : " name" ,
35+ "required" : true
3136 }
3237 }
3338}
Original file line number Diff line number Diff line change 66
77const { createCoreService } = require ( '@strapi/strapi' ) . factories ;
88
9- module . exports = createCoreService ( 'api::collection.collection' ) ;
9+ module . exports = createCoreService ( 'api::collection.collection' , ( { strapi} ) => ( {
10+ async findByUid ( ctx ) {
11+ const ctUid = 'api::collection.collection' ;
12+ const attrs = strapi . contentTypes [ ctUid ] . __schema__ . attributes ;
13+ const uidTarget = attrs [ 'uid' ] . targetField ;
14+ const { [ uidTarget ] : uidTargetValue } = ctx . params ;
15+
16+ const populateParams = strapi . config . functions . getPopulateParams ( attrs ) ;
17+
18+ let entity = await strapi . db . query ( ctUid ) . findOne ( {
19+ where : { [ uidTarget ] : uidTargetValue } ,
20+ populate : populateParams
21+ } ) ;
22+
23+ if ( entity ) {
24+ entity = strapi . config . functions . reduceComponentData ( attrs , entity ) ;
25+ }
26+
27+ return entity ;
28+ }
29+ } ) ) ;
Original file line number Diff line number Diff line change 1+ module . exports = {
2+ async beforeCreate ( event ) {
3+ event . params . data . uid = await strapi . service ( 'plugin::content-manager.uid' )
4+ . generateUIDField ( {
5+ contentTypeUID : 'api::team.team' ,
6+ field : 'uid' ,
7+ data : event . params . data
8+ } ) ;
9+ } ,
10+ async beforeUpdate ( event ) {
11+ const { data, where } = event . params ;
12+
13+ const isPublishAction = 'publishedAt' in data ;
14+
15+ if ( ! isPublishAction ) {
16+ const entry = await strapi . entityService . findOne ( 'api::team.team' , where . id ) ;
17+
18+ if ( 'name' in data && data . name !== entry . name ) {
19+ event . params . data . uid = await strapi . service ( 'plugin::content-manager.uid' )
20+ . generateUIDField ( {
21+ contentTypeUID : 'api::team.team' ,
22+ field : 'uid' ,
23+ data : data
24+ } ) ;
25+ }
26+ }
27+ } ,
28+ } ;
Original file line number Diff line number Diff line change 4242 },
4343 "email" : {
4444 "type" : " email"
45+ },
46+ "uid" : {
47+ "type" : " uid" ,
48+ "targetField" : " name" ,
49+ "required" : true
4550 }
4651 }
4752}
Original file line number Diff line number Diff line change 66
77const { createCoreService } = require ( '@strapi/strapi' ) . factories ;
88
9- module . exports = createCoreService ( 'api::team.team' ) ;
9+ module . exports = createCoreService ( 'api::team.team' , ( { strapi} ) => ( {
10+ async findByUid ( ctx ) {
11+ const ctUid = 'api::team.team' ;
12+ const attrs = strapi . contentTypes [ ctUid ] . __schema__ . attributes ;
13+ const uidTarget = attrs [ 'uid' ] . targetField ;
14+ const { [ uidTarget ] : uidTargetValue } = ctx . params ;
15+
16+ const populateParams = strapi . config . functions . getPopulateParams ( attrs ) ;
17+
18+ let entity = await strapi . db . query ( ctUid ) . findOne ( {
19+ where : { [ uidTarget ] : uidTargetValue } ,
20+ populate : populateParams
21+ } ) ;
22+
23+ if ( entity ) {
24+ entity = strapi . config . functions . reduceComponentData ( attrs , entity ) ;
25+ }
26+
27+ return entity ;
28+ }
29+ } ) ) ;
Original file line number Diff line number Diff line change 11'use strict' ;
22
3+ const { ApplicationError } = require ( '@strapi/utils' ) . errors ;
34const array = require ( 'lodash/array' ) ;
45const collection = require ( 'lodash/collection' ) ;
56const object = require ( 'lodash/object' ) ;
@@ -22,10 +23,10 @@ const getEbiFieldData = async (data, ontology) => {
2223 ( { options} = res ) ;
2324
2425 if ( error ) {
25- throw new Error ( error ) ;
26+ throw new ApplicationError ( error ) ;
2627 }
2728 else if ( ! options || ! options . length ) {
28- throw new Error ( `Provided data ${ q } does not match to any ontology` ) ;
29+ throw new ApplicationError ( `Provided data ${ q } does not match to any ontology` ) ;
2930 }
3031
3132 if ( label ) {
@@ -34,7 +35,7 @@ const getEbiFieldData = async (data, ontology) => {
3435 ) ;
3536 }
3637 if ( options . length > 1 ) {
37- throw new Error ( `Provided data ${ q } does not match to a single ontology` ) ;
38+ throw new ApplicationError ( `Provided data ${ q } does not match to a single ontology` ) ;
3839 }
3940
4041 return options [ 0 ] ;
You can’t perform that action at this time.
0 commit comments