|
|
@ -12,6 +12,7 @@ import NocoCache from '../cache/NocoCache'; |
|
|
|
import CryptoJS from 'crypto-js'; |
|
|
|
import CryptoJS from 'crypto-js'; |
|
|
|
import { extractProps } from '../meta/helpers/extractProps'; |
|
|
|
import { extractProps } from '../meta/helpers/extractProps'; |
|
|
|
import { NcError } from '../meta/helpers/catchError'; |
|
|
|
import { NcError } from '../meta/helpers/catchError'; |
|
|
|
|
|
|
|
import SyncSource from './SyncSource'; |
|
|
|
|
|
|
|
|
|
|
|
// todo: hide credentials
|
|
|
|
// todo: hide credentials
|
|
|
|
export default class Base implements BaseType { |
|
|
|
export default class Base implements BaseType { |
|
|
@ -89,18 +90,13 @@ export default class Base implements BaseType { |
|
|
|
|
|
|
|
|
|
|
|
if (!oldBase) NcError.badRequest('Wrong base id!'); |
|
|
|
if (!oldBase) NcError.badRequest('Wrong base id!'); |
|
|
|
|
|
|
|
|
|
|
|
await ncMeta.metaDelete(null, null, MetaTable.BASES, { |
|
|
|
|
|
|
|
id: baseId, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await NocoCache.deepDel( |
|
|
|
await NocoCache.deepDel( |
|
|
|
CacheScope.BASE, |
|
|
|
CacheScope.BASE, |
|
|
|
`${CacheScope.BASE}:${baseId}`, |
|
|
|
`${CacheScope.BASE}:${baseId}`, |
|
|
|
CacheDelDirection.CHILD_TO_PARENT |
|
|
|
CacheDelDirection.CHILD_TO_PARENT |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const insertObj = extractProps(base, [ |
|
|
|
const updateObj = extractProps(base, [ |
|
|
|
'id', |
|
|
|
|
|
|
|
'alias', |
|
|
|
'alias', |
|
|
|
'config', |
|
|
|
'config', |
|
|
|
'type', |
|
|
|
'type', |
|
|
@ -112,42 +108,37 @@ export default class Base implements BaseType { |
|
|
|
'order', |
|
|
|
'order', |
|
|
|
'enabled', |
|
|
|
'enabled', |
|
|
|
]); |
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
|
if (insertObj.config) { |
|
|
|
if (updateObj.config) { |
|
|
|
insertObj.config = CryptoJS.AES.encrypt( |
|
|
|
updateObj.config = CryptoJS.AES.encrypt( |
|
|
|
JSON.stringify(base.config), |
|
|
|
JSON.stringify(base.config), |
|
|
|
Noco.getConfig()?.auth?.jwt?.secret |
|
|
|
Noco.getConfig()?.auth?.jwt?.secret |
|
|
|
).toString(); |
|
|
|
).toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// type property is undefined even if not provided
|
|
|
|
// type property is undefined even if not provided
|
|
|
|
if (!insertObj.type) { |
|
|
|
if (!updateObj.type) { |
|
|
|
insertObj.type = oldBase.type; |
|
|
|
updateObj.type = oldBase.type; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// add missing (not updated) fields
|
|
|
|
await ncMeta.metaUpdate( |
|
|
|
const finalInsertObj = { |
|
|
|
|
|
|
|
...oldBase, |
|
|
|
|
|
|
|
...insertObj, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { id } = await ncMeta.metaInsert2( |
|
|
|
|
|
|
|
base.projectId, |
|
|
|
base.projectId, |
|
|
|
null, |
|
|
|
null, |
|
|
|
MetaTable.BASES, |
|
|
|
MetaTable.BASES, |
|
|
|
finalInsertObj |
|
|
|
updateObj, |
|
|
|
|
|
|
|
oldBase.id |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await NocoCache.appendToList( |
|
|
|
await NocoCache.appendToList( |
|
|
|
CacheScope.BASE, |
|
|
|
CacheScope.BASE, |
|
|
|
[base.projectId], |
|
|
|
[base.projectId], |
|
|
|
`${CacheScope.BASE}:${id}` |
|
|
|
`${CacheScope.BASE}:${oldBase.id}` |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// call before reorder to update cache
|
|
|
|
// call before reorder to update cache
|
|
|
|
const returnBase = await this.get(id, ncMeta); |
|
|
|
const returnBase = await this.get(oldBase.id, ncMeta); |
|
|
|
|
|
|
|
|
|
|
|
await this.reorderBases(base.projectId, id, ncMeta); |
|
|
|
await this.reorderBases(base.projectId, returnBase.id, ncMeta); |
|
|
|
|
|
|
|
|
|
|
|
return returnBase; |
|
|
|
return returnBase; |
|
|
|
} |
|
|
|
} |
|
|
@ -217,9 +208,6 @@ export default class Base implements BaseType { |
|
|
|
|
|
|
|
|
|
|
|
// update order for bases
|
|
|
|
// update order for bases
|
|
|
|
for (const [i, b] of Object.entries(bases)) { |
|
|
|
for (const [i, b] of Object.entries(bases)) { |
|
|
|
await ncMeta.metaDelete(null, null, MetaTable.BASES, { |
|
|
|
|
|
|
|
id: b.id, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await NocoCache.deepDel( |
|
|
|
await NocoCache.deepDel( |
|
|
|
CacheScope.BASE, |
|
|
|
CacheScope.BASE, |
|
|
@ -229,20 +217,23 @@ export default class Base implements BaseType { |
|
|
|
|
|
|
|
|
|
|
|
b.order = parseInt(i) + 1; |
|
|
|
b.order = parseInt(i) + 1; |
|
|
|
|
|
|
|
|
|
|
|
const { id } = await ncMeta.metaInsert2( |
|
|
|
await ncMeta.metaUpdate( |
|
|
|
b.project_id, |
|
|
|
b.project_id, |
|
|
|
null, |
|
|
|
null, |
|
|
|
MetaTable.BASES, |
|
|
|
MetaTable.BASES, |
|
|
|
b |
|
|
|
{ |
|
|
|
|
|
|
|
order: b.order |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
b.id |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await NocoCache.appendToList( |
|
|
|
await NocoCache.appendToList( |
|
|
|
CacheScope.BASE, |
|
|
|
CacheScope.BASE, |
|
|
|
[b.project_id], |
|
|
|
[b.project_id], |
|
|
|
`${CacheScope.BASE}:${id}` |
|
|
|
`${CacheScope.BASE}:${b.id}` |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await NocoCache.set(`${CacheScope.BASE}:${id}`, b); |
|
|
|
await NocoCache.set(`${CacheScope.BASE}:${b.id}`, b); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -299,6 +290,12 @@ export default class Base implements BaseType { |
|
|
|
`${CacheScope.BASE}:${this.id}`, |
|
|
|
`${CacheScope.BASE}:${this.id}`, |
|
|
|
CacheDelDirection.CHILD_TO_PARENT |
|
|
|
CacheDelDirection.CHILD_TO_PARENT |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const syncSources = await SyncSource.list(this.project_id, this.id, ncMeta); |
|
|
|
|
|
|
|
for (const syncSource of syncSources) { |
|
|
|
|
|
|
|
await SyncSource.delete(syncSource.id, ncMeta); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return await ncMeta.metaDelete(null, null, MetaTable.BASES, this.id); |
|
|
|
return await ncMeta.metaDelete(null, null, MetaTable.BASES, this.id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|