fix: discussions

pull/40/head
tilman 2022-01-17 17:46:02 +01:00
parent 997badd17c
commit 4b9687a454
6 changed files with 17 additions and 12513 deletions

1
.gitignore vendored
View File

@ -3,6 +3,7 @@ coverage
node_modules node_modules
stats.json stats.json
package-lock.json package-lock.json
yarn.lock
files files
# Cruft # Cruft

0
bin/config-sync Normal file → Executable file
View File

View File

@ -53,7 +53,7 @@
"strapi-server.js" "strapi-server.js"
], ],
"peerDependencies": { "peerDependencies": {
"@strapi/strapi": "^4.0.0" "@strapi/strapi": "^4.0.4"
}, },
"devDependencies": { "devDependencies": {
"@fortawesome/react-fontawesome": "^0.1.16", "@fortawesome/react-fontawesome": "^0.1.16",

View File

@ -48,20 +48,11 @@ const ConfigType = class ConfigType {
populate: this.relations.map(({ relationName }) => relationName), 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 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 }) => { await Promise.all(this.relations.map(async ({ queryString, parentName }) => {
const relations = await noLimit(strapi.query(queryString), { const relations = await noLimit(strapi.query(queryString), {
where: { where: {
[parentName]: entity.id, [parentName]: existingConfig.id,
}, },
}); });
@ -73,7 +64,7 @@ const ConfigType = class ConfigType {
})); }));
await queryAPI.delete({ await queryAPI.delete({
where: { id: entity.id }, where: { id: existingConfig.id },
}); });
return; return;

View File

@ -1,11 +1,20 @@
'use strict'; 'use strict';
const COMBINED_UID_JOINSTR = ', '; const COMBINED_UID_JOINSTR = '+.+';
const escapeUid = (uid) => uid.replace(/,/g, '').replace(COMBINED_UID_JOINSTR, ''); const escapeUid = (uid) => typeof uid === "string" ? uid.replace(/\+\.\+/g, '+_._+') : uid;
const getCombinedUid = (uidKeys, params) => uidKeys.map((uidKey) => params[uidKey]).join(COMBINED_UID_JOINSTR); 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 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 = () => { const getCoreStore = () => {
return strapi.store({ type: 'plugin', name: 'config-sync' }); return strapi.store({ type: 'plugin', name: 'config-sync' });
@ -90,7 +99,6 @@ const noLimit = async (query, parameters, limit = 100) => {
}; };
module.exports = { module.exports = {
escapeUid,
getCombinedUid, getCombinedUid,
getCombinedUidWhereFilter, getCombinedUidWhereFilter,
getUidParamsFromName, getUidParamsFromName,

12496
yarn.lock

File diff suppressed because it is too large Load Diff