@@ -67,20 +67,28 @@ const decorator = (service: IDecoratedService) => ({
67
67
return service . update . call ( this , uid , entityId , opts ) ;
68
68
}
69
69
70
+ // Manually fetch the entity that's being updated.
71
+ // We do this becuase not all it's data is present in opts.data.
72
+ const entity = await service . findOne . call ( this , uid , entityId , {
73
+ populate : {
74
+ url_alias : {
75
+ fields : [ 'id' , 'generated' ] ,
76
+ } ,
77
+ } ,
78
+ } ) ;
79
+
70
80
// If a URL alias is allready present, fetch it.
71
81
if ( opts . data . url_alias ) {
72
82
urlAliasEntity = await getPluginService ( 'urlAliasService' ) . findOne ( opts . data . url_alias ) ;
83
+ } else if ( entity . url_alias ) {
84
+ urlAliasEntity = entity . url_alias ;
73
85
}
74
86
75
87
// If a URL alias is present and 'generated' is set to false, do nothing.
76
88
if ( urlAliasEntity ?. generated === false ) {
77
89
return service . update . call ( this , uid , entityId , opts ) ;
78
90
}
79
91
80
- // Manually fetch the entity that's being updated.
81
- // We do this becuase not all it's data is present in opts.data.
82
- const entity = await service . findOne . call ( this , uid , entityId ) ;
83
-
84
92
// Generate the path.
85
93
const generatedPath = await getPluginService ( 'urlPatternService' ) . resolvePattern ( uid , { ...entity , ...opts . data } ) ;
86
94
@@ -95,7 +103,13 @@ const decorator = (service: IDecoratedService) => ({
95
103
}
96
104
97
105
// Eventually update the entity.
98
- return service . update . call ( this , uid , entityId , opts ) ;
106
+ return service . update . call ( this , uid , entityId , {
107
+ ...opts ,
108
+ data : {
109
+ ...opts . data ,
110
+ url_alias : urlAliasEntity . id ,
111
+ } ,
112
+ } ) ;
99
113
} ,
100
114
async delete ( uid : Common . UID . ContentType , entityId : number ) {
101
115
const hasWT = isContentTypeEnabled ( uid ) ;
@@ -106,18 +120,17 @@ const decorator = (service: IDecoratedService) => ({
106
120
}
107
121
108
122
// Fetch the entity because we need the url_alias id.
109
- const entity = await strapi . entityService . findOne ( uid , entityId , {
110
- // @ts -ignore
111
- populate : 'url_alias' ,
123
+ const entity = await service . findOne . call ( this , uid , entityId , {
124
+ populate : {
125
+ url_alias : {
126
+ fields : [ 'id' ] ,
127
+ } ,
128
+ } ,
112
129
} ) ;
113
130
114
131
// If a URL alias is present, delete it.
115
- // @ts -ignore
116
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
117
132
if ( entity . url_alias ?. id ) {
118
- // @ts -ignore
119
- // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
120
- await getPluginService ( 'urlAliasService' ) . delete ( Number ( entity . url_alias . id ) ) ;
133
+ await getPluginService ( 'urlAliasService' ) . delete ( entity . url_alias . id ) ;
121
134
}
122
135
123
136
// Eventually delete the entity.
0 commit comments