fix: discussions
parent
997badd17c
commit
4b9687a454
|
@ -3,6 +3,7 @@ coverage
|
|||
node_modules
|
||||
stats.json
|
||||
package-lock.json
|
||||
yarn.lock
|
||||
files
|
||||
|
||||
# Cruft
|
||||
|
|
|
@ -53,7 +53,7 @@
|
|||
"strapi-server.js"
|
||||
],
|
||||
"peerDependencies": {
|
||||
"@strapi/strapi": "^4.0.0"
|
||||
"@strapi/strapi": "^4.0.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@fortawesome/react-fontawesome": "^0.1.16",
|
||||
|
|
|
@ -48,20 +48,11 @@ const ConfigType = class ConfigType {
|
|||
populate: this.relations.map(({ relationName }) => relationName),
|
||||
});
|
||||
|
||||
console.log("importSingle", configName, uidParams, existingConfig, configContent, combinedUidWhereFilter)
|
||||
|
||||
if (existingConfig && configContent === null) { // Config exists in DB but no configfile content --> delete config from DB
|
||||
// was there a reason to fetch it again? Isn't this the same as existingConfig?
|
||||
// const entity = await queryAPI.findOne({
|
||||
// where: combinedUidWhereFilter,
|
||||
// populate: this.relations.map(({ relationName }) => relationName),
|
||||
// });
|
||||
const entity = existingConfig;
|
||||
|
||||
await Promise.all(this.relations.map(async ({ queryString, parentName }) => {
|
||||
const relations = await noLimit(strapi.query(queryString), {
|
||||
where: {
|
||||
[parentName]: entity.id,
|
||||
[parentName]: existingConfig.id,
|
||||
},
|
||||
});
|
||||
|
||||
|
@ -73,7 +64,7 @@ const ConfigType = class ConfigType {
|
|||
}));
|
||||
|
||||
await queryAPI.delete({
|
||||
where: { id: entity.id },
|
||||
where: { id: existingConfig.id },
|
||||
});
|
||||
|
||||
return;
|
||||
|
|
|
@ -1,11 +1,20 @@
|
|||
'use strict';
|
||||
|
||||
const COMBINED_UID_JOINSTR = ', ';
|
||||
const COMBINED_UID_JOINSTR = '+.+';
|
||||
|
||||
const escapeUid = (uid) => uid.replace(/,/g, '').replace(COMBINED_UID_JOINSTR, '');
|
||||
const getCombinedUid = (uidKeys, params) => uidKeys.map((uidKey) => params[uidKey]).join(COMBINED_UID_JOINSTR);
|
||||
const escapeUid = (uid) => typeof uid === "string" ? uid.replace(/\+\.\+/g, '+_._+') : uid;
|
||||
const unEscapeUid = (uid) => typeof uid === "string" ? uid.replace(/\+_\._\+_/g, '+.+') : uid;
|
||||
const getCombinedUid = (uidKeys, params) => {
|
||||
const res = uidKeys.map((uidKey) => escapeUid(params[uidKey])).join(COMBINED_UID_JOINSTR);
|
||||
console.log("getCombinedUid", res);
|
||||
return res;
|
||||
};
|
||||
const getCombinedUidWhereFilter = (uidKeys, params) => uidKeys.reduce(((akku, uidKey) => ({ ...akku, [uidKey]: params[uidKey] })), {});
|
||||
const getUidParamsFromName = (uidKeys, configName) => configName.split(COMBINED_UID_JOINSTR).reduce((akku, param, i) => ({ ...akku, [uidKeys[i]]: param }), {});
|
||||
const getUidParamsFromName = (uidKeys, configName) => {
|
||||
const res = configName.split(COMBINED_UID_JOINSTR).map(unEscapeUid).reduce((akku, param, i) => ({ ...akku, [uidKeys[i]]: param }), {});
|
||||
console.log("getUidParamsFromName", res);
|
||||
return res;
|
||||
};
|
||||
|
||||
const getCoreStore = () => {
|
||||
return strapi.store({ type: 'plugin', name: 'config-sync' });
|
||||
|
@ -90,7 +99,6 @@ const noLimit = async (query, parameters, limit = 100) => {
|
|||
};
|
||||
|
||||
module.exports = {
|
||||
escapeUid,
|
||||
getCombinedUid,
|
||||
getCombinedUidWhereFilter,
|
||||
getUidParamsFromName,
|
||||
|
|
Loading…
Reference in New Issue