|
|
@ -8,6 +8,7 @@ import { nocoExecute } from 'nc-help'; |
|
|
|
import { |
|
|
|
import { |
|
|
|
AuditOperationSubTypes, |
|
|
|
AuditOperationSubTypes, |
|
|
|
AuditOperationTypes, |
|
|
|
AuditOperationTypes, |
|
|
|
|
|
|
|
isCreatedOrLastModifiedByCol, |
|
|
|
isCreatedOrLastModifiedTimeCol, |
|
|
|
isCreatedOrLastModifiedTimeCol, |
|
|
|
isLinksOrLTAR, |
|
|
|
isLinksOrLTAR, |
|
|
|
isSystemColumn, |
|
|
|
isSystemColumn, |
|
|
@ -103,7 +104,11 @@ function checkColumnRequired( |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function getColumnName(column: Column<any>, columns?: Column[]) { |
|
|
|
export async function getColumnName(column: Column<any>, columns?: Column[]) { |
|
|
|
if (!isCreatedOrLastModifiedTimeCol(column)) return column.column_name; |
|
|
|
if ( |
|
|
|
|
|
|
|
!isCreatedOrLastModifiedTimeCol(column) && |
|
|
|
|
|
|
|
!isCreatedOrLastModifiedByCol(column) |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
return column.column_name; |
|
|
|
columns = columns || (await Column.list({ fk_model_id: column.fk_model_id })); |
|
|
|
columns = columns || (await Column.list({ fk_model_id: column.fk_model_id })); |
|
|
|
|
|
|
|
|
|
|
|
switch (column.uidt) { |
|
|
|
switch (column.uidt) { |
|
|
@ -122,6 +127,20 @@ export async function getColumnName(column: Column<any>, columns?: Column[]) { |
|
|
|
return lastModifiedTimeSystemCol.column_name; |
|
|
|
return lastModifiedTimeSystemCol.column_name; |
|
|
|
return column.column_name || 'updated_at'; |
|
|
|
return column.column_name || 'updated_at'; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
case UITypes.CreatedBy: { |
|
|
|
|
|
|
|
const createdBySystemCol = columns.find( |
|
|
|
|
|
|
|
(col) => col.system && col.uidt === UITypes.CreatedBy, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
if (createdBySystemCol) return createdBySystemCol.column_name; |
|
|
|
|
|
|
|
return column.column_name || 'created_by'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case UITypes.LastModifiedBy: { |
|
|
|
|
|
|
|
const lastModifiedBySystemCol = columns.find( |
|
|
|
|
|
|
|
(col) => col.system && col.uidt === UITypes.LastModifiedBy, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
if (lastModifiedBySystemCol) return lastModifiedBySystemCol.column_name; |
|
|
|
|
|
|
|
return column.column_name || 'updated_by'; |
|
|
|
|
|
|
|
} |
|
|
|
default: |
|
|
|
default: |
|
|
|
return column.column_name; |
|
|
|
return column.column_name; |
|
|
|
} |
|
|
|
} |
|
|
@ -739,7 +758,16 @@ class BaseModelSqlv2 { |
|
|
|
|
|
|
|
|
|
|
|
const column = groupByColumns[sort.fk_column_id]; |
|
|
|
const column = groupByColumns[sort.fk_column_id]; |
|
|
|
|
|
|
|
|
|
|
|
if (column.uidt === UITypes.User) { |
|
|
|
if ( |
|
|
|
|
|
|
|
[UITypes.User, UITypes.CreatedBy, UITypes.LastModifiedBy].includes( |
|
|
|
|
|
|
|
column.uidt as UITypes, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
const columnName = await getColumnName( |
|
|
|
|
|
|
|
column, |
|
|
|
|
|
|
|
await this.model.getColumns(), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
const baseUsers = await BaseUser.getUsersList({ |
|
|
|
const baseUsers = await BaseUser.getUsersList({ |
|
|
|
base_id: column.base_id, |
|
|
|
base_id: column.base_id, |
|
|
|
}); |
|
|
|
}); |
|
|
@ -751,7 +779,7 @@ class BaseModelSqlv2 { |
|
|
|
user.display_name || user.email, |
|
|
|
user.display_name || user.email, |
|
|
|
]); |
|
|
|
]); |
|
|
|
return qb.toQuery(); |
|
|
|
return qb.toQuery(); |
|
|
|
}, this.dbDriver.raw(`??`, [column.column_name]).toQuery()); |
|
|
|
}, this.dbDriver.raw(`??`, [columnName]).toQuery()); |
|
|
|
|
|
|
|
|
|
|
|
qb.orderBy( |
|
|
|
qb.orderBy( |
|
|
|
sanitize(this.dbDriver.raw(finalStatement)), |
|
|
|
sanitize(this.dbDriver.raw(finalStatement)), |
|
|
@ -2314,6 +2342,18 @@ class BaseModelSqlv2 { |
|
|
|
).builder.as(sanitize(column.id)), |
|
|
|
).builder.as(sanitize(column.id)), |
|
|
|
); |
|
|
|
); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
case UITypes.CreatedBy: |
|
|
|
|
|
|
|
case UITypes.LastModifiedBy: { |
|
|
|
|
|
|
|
const columnName = await getColumnName( |
|
|
|
|
|
|
|
column, |
|
|
|
|
|
|
|
await this.model.getColumns(), |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
res[sanitize(column.id || columnName)] = sanitize( |
|
|
|
|
|
|
|
`${alias || this.tnPath}.${columnName}`, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
default: |
|
|
|
default: |
|
|
|
if (this.isPg) { |
|
|
|
if (this.isPg) { |
|
|
|
if (column.dt === 'bytea') { |
|
|
|
if (column.dt === 'bytea') { |
|
|
@ -2368,7 +2408,7 @@ class BaseModelSqlv2 { |
|
|
|
await this.beforeInsert(insertObj, trx, cookie); |
|
|
|
await this.beforeInsert(insertObj, trx, cookie); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await this.prepareNocoData(insertObj, true); |
|
|
|
await this.prepareNocoData(insertObj, true, cookie); |
|
|
|
|
|
|
|
|
|
|
|
let response; |
|
|
|
let response; |
|
|
|
// const driver = trx ? trx : this.dbDriver;
|
|
|
|
// const driver = trx ? trx : this.dbDriver;
|
|
|
@ -2613,7 +2653,7 @@ class BaseModelSqlv2 { |
|
|
|
|
|
|
|
|
|
|
|
await this.beforeUpdate(data, trx, cookie); |
|
|
|
await this.beforeUpdate(data, trx, cookie); |
|
|
|
|
|
|
|
|
|
|
|
await this.prepareNocoData(updateObj); |
|
|
|
await this.prepareNocoData(updateObj, false, cookie); |
|
|
|
|
|
|
|
|
|
|
|
const prevData = await this.readByPk( |
|
|
|
const prevData = await this.readByPk( |
|
|
|
id, |
|
|
|
id, |
|
|
@ -2734,7 +2774,7 @@ class BaseModelSqlv2 { |
|
|
|
|
|
|
|
|
|
|
|
await this.beforeInsert(insertObj, this.dbDriver, cookie); |
|
|
|
await this.beforeInsert(insertObj, this.dbDriver, cookie); |
|
|
|
|
|
|
|
|
|
|
|
await this.prepareNocoData(insertObj, true); |
|
|
|
await this.prepareNocoData(insertObj, true, cookie); |
|
|
|
|
|
|
|
|
|
|
|
let response; |
|
|
|
let response; |
|
|
|
const query = this.dbDriver(this.tnPath).insert(insertObj); |
|
|
|
const query = this.dbDriver(this.tnPath).insert(insertObj); |
|
|
@ -2962,7 +3002,11 @@ class BaseModelSqlv2 { |
|
|
|
for (let i = 0; i < this.model.columns.length; ++i) { |
|
|
|
for (let i = 0; i < this.model.columns.length; ++i) { |
|
|
|
const col = this.model.columns[i]; |
|
|
|
const col = this.model.columns[i]; |
|
|
|
|
|
|
|
|
|
|
|
if (col.title in d && isCreatedOrLastModifiedTimeCol(col)) { |
|
|
|
if ( |
|
|
|
|
|
|
|
col.title in d && |
|
|
|
|
|
|
|
(isCreatedOrLastModifiedTimeCol(col) || |
|
|
|
|
|
|
|
isCreatedOrLastModifiedByCol(col)) |
|
|
|
|
|
|
|
) { |
|
|
|
NcError.badRequest( |
|
|
|
NcError.badRequest( |
|
|
|
`Column "${col.title}" is auto generated and cannot be updated`, |
|
|
|
`Column "${col.title}" is auto generated and cannot be updated`, |
|
|
|
); |
|
|
|
); |
|
|
@ -3085,7 +3129,7 @@ class BaseModelSqlv2 { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await this.prepareNocoData(insertObj, true); |
|
|
|
await this.prepareNocoData(insertObj, true, cookie); |
|
|
|
|
|
|
|
|
|
|
|
// prepare nested link data for insert only if it is single record insertion
|
|
|
|
// prepare nested link data for insert only if it is single record insertion
|
|
|
|
if (isSingleRecordInsertion) { |
|
|
|
if (isSingleRecordInsertion) { |
|
|
@ -3229,7 +3273,7 @@ class BaseModelSqlv2 { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!raw) { |
|
|
|
if (!raw) { |
|
|
|
await this.prepareNocoData(d); |
|
|
|
await this.prepareNocoData(d, false, cookie); |
|
|
|
|
|
|
|
|
|
|
|
const oldRecord = await this.readByPk(pkValues); |
|
|
|
const oldRecord = await this.readByPk(pkValues); |
|
|
|
if (!oldRecord) { |
|
|
|
if (!oldRecord) { |
|
|
@ -3302,6 +3346,9 @@ class BaseModelSqlv2 { |
|
|
|
this.dbDriver, |
|
|
|
this.dbDriver, |
|
|
|
); |
|
|
|
); |
|
|
|
if (!args.skipValidationAndHooks) await this.validate(updateData); |
|
|
|
if (!args.skipValidationAndHooks) await this.validate(updateData); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await this.prepareNocoData(updateData, false, cookie); |
|
|
|
|
|
|
|
|
|
|
|
const pkValues = await this._extractPksValues(updateData); |
|
|
|
const pkValues = await this._extractPksValues(updateData); |
|
|
|
if (pkValues) { |
|
|
|
if (pkValues) { |
|
|
|
// pk is specified - by pass
|
|
|
|
// pk is specified - by pass
|
|
|
@ -3847,7 +3894,11 @@ class BaseModelSqlv2 { |
|
|
|
for (let i = 0; i < this.model.columns.length; ++i) { |
|
|
|
for (let i = 0; i < this.model.columns.length; ++i) { |
|
|
|
const column = this.model.columns[i]; |
|
|
|
const column = this.model.columns[i]; |
|
|
|
|
|
|
|
|
|
|
|
if (column.title in data && isCreatedOrLastModifiedTimeCol(column)) { |
|
|
|
if ( |
|
|
|
|
|
|
|
column.title in data && |
|
|
|
|
|
|
|
(isCreatedOrLastModifiedTimeCol(column) || |
|
|
|
|
|
|
|
isCreatedOrLastModifiedByCol(column)) |
|
|
|
|
|
|
|
) { |
|
|
|
NcError.badRequest( |
|
|
|
NcError.badRequest( |
|
|
|
`Column "${column.title}" is auto generated and cannot be updated`, |
|
|
|
`Column "${column.title}" is auto generated and cannot be updated`, |
|
|
|
); |
|
|
|
); |
|
|
@ -4018,13 +4069,15 @@ class BaseModelSqlv2 { |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await this.updateLastModifiedTime({ |
|
|
|
await this.updateLastModified({ |
|
|
|
model: parentTable, |
|
|
|
model: parentTable, |
|
|
|
rowIds: [childId], |
|
|
|
rowIds: [childId], |
|
|
|
|
|
|
|
cookie, |
|
|
|
}); |
|
|
|
}); |
|
|
|
await this.updateLastModifiedTime({ |
|
|
|
await this.updateLastModified({ |
|
|
|
model: childTable, |
|
|
|
model: childTable, |
|
|
|
rowIds: [rowId], |
|
|
|
rowIds: [rowId], |
|
|
|
|
|
|
|
cookie, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -4046,9 +4099,10 @@ class BaseModelSqlv2 { |
|
|
|
{ raw: true }, |
|
|
|
{ raw: true }, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await this.updateLastModifiedTime({ |
|
|
|
await this.updateLastModified({ |
|
|
|
model: parentTable, |
|
|
|
model: parentTable, |
|
|
|
rowIds: [rowId], |
|
|
|
rowIds: [rowId], |
|
|
|
|
|
|
|
cookie, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -4070,9 +4124,10 @@ class BaseModelSqlv2 { |
|
|
|
{ raw: true }, |
|
|
|
{ raw: true }, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await this.updateLastModifiedTime({ |
|
|
|
await this.updateLastModified({ |
|
|
|
model: parentTable, |
|
|
|
model: parentTable, |
|
|
|
rowIds: [childId], |
|
|
|
rowIds: [childId], |
|
|
|
|
|
|
|
cookie, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -4168,13 +4223,15 @@ class BaseModelSqlv2 { |
|
|
|
{ raw: true }, |
|
|
|
{ raw: true }, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await this.updateLastModifiedTime({ |
|
|
|
await this.updateLastModified({ |
|
|
|
model: parentTable, |
|
|
|
model: parentTable, |
|
|
|
rowIds: [childId], |
|
|
|
rowIds: [childId], |
|
|
|
|
|
|
|
cookie, |
|
|
|
}); |
|
|
|
}); |
|
|
|
await this.updateLastModifiedTime({ |
|
|
|
await this.updateLastModified({ |
|
|
|
model: childTable, |
|
|
|
model: childTable, |
|
|
|
rowIds: [rowId], |
|
|
|
rowIds: [rowId], |
|
|
|
|
|
|
|
cookie, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -4194,9 +4251,10 @@ class BaseModelSqlv2 { |
|
|
|
{ raw: true }, |
|
|
|
{ raw: true }, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await this.updateLastModifiedTime({ |
|
|
|
await this.updateLastModified({ |
|
|
|
model: parentTable, |
|
|
|
model: parentTable, |
|
|
|
rowIds: [rowId], |
|
|
|
rowIds: [rowId], |
|
|
|
|
|
|
|
cookie, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -4216,9 +4274,10 @@ class BaseModelSqlv2 { |
|
|
|
{ raw: true }, |
|
|
|
{ raw: true }, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await this.updateLastModifiedTime({ |
|
|
|
await this.updateLastModified({ |
|
|
|
model: parentTable, |
|
|
|
model: parentTable, |
|
|
|
rowIds: [childId], |
|
|
|
rowIds: [childId], |
|
|
|
|
|
|
|
cookie, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -4660,22 +4719,43 @@ class BaseModelSqlv2 { |
|
|
|
await this.model.getColumns(); |
|
|
|
await this.model.getColumns(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const userColumns = []; |
|
|
|
let userColumns = []; |
|
|
|
|
|
|
|
|
|
|
|
const columns = childTable ? childTable.columns : this.model.columns; |
|
|
|
const columns = childTable ? childTable.columns : this.model.columns; |
|
|
|
|
|
|
|
|
|
|
|
for (const col of columns) { |
|
|
|
for (const col of columns) { |
|
|
|
if (col.uidt === UITypes.Lookup) { |
|
|
|
if (col.uidt === UITypes.Lookup) { |
|
|
|
if ((await this.getNestedUidt(col)) === UITypes.User) { |
|
|
|
if ( |
|
|
|
|
|
|
|
[UITypes.User, UITypes.CreatedBy, UITypes.LastModifiedBy].includes( |
|
|
|
|
|
|
|
(await this.getNestedUidt(col)) as UITypes, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) { |
|
|
|
userColumns.push(col); |
|
|
|
userColumns.push(col); |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (col.uidt === UITypes.User) { |
|
|
|
if ( |
|
|
|
|
|
|
|
[UITypes.User, UITypes.CreatedBy, UITypes.LastModifiedBy].includes( |
|
|
|
|
|
|
|
col.uidt, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) { |
|
|
|
userColumns.push(col); |
|
|
|
userColumns.push(col); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// filter user columns that are not present in data
|
|
|
|
|
|
|
|
if (userColumns.length) { |
|
|
|
|
|
|
|
if (Array.isArray(data)) { |
|
|
|
|
|
|
|
const row = data[0]; |
|
|
|
|
|
|
|
if (row) { |
|
|
|
|
|
|
|
userColumns = userColumns.filter((col) => col.id in row); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
userColumns = userColumns.filter((col) => col.id in data); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// process user columns that are present in data
|
|
|
|
if (userColumns.length) { |
|
|
|
if (userColumns.length) { |
|
|
|
const baseUsers = await BaseUser.getUsersList({ |
|
|
|
const baseUsers = await BaseUser.getUsersList({ |
|
|
|
base_id: childTable ? childTable.base_id : this.model.base_id, |
|
|
|
base_id: childTable ? childTable.base_id : this.model.base_id, |
|
|
@ -4694,30 +4774,32 @@ class BaseModelSqlv2 { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected _convertUserFormat( |
|
|
|
protected _convertUserFormat( |
|
|
|
userColumns: Record<string, any>[], |
|
|
|
userColumns: Column[], |
|
|
|
baseUsers: Partial<User>[], |
|
|
|
baseUsers: Partial<User>[], |
|
|
|
d: Record<string, any>, |
|
|
|
d: Record<string, any>, |
|
|
|
) { |
|
|
|
) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
if (d) { |
|
|
|
if (d) { |
|
|
|
for (const col of userColumns) { |
|
|
|
const availableUserColumns = userColumns.filter( |
|
|
|
if (d[col.id] && d[col.id].length) { |
|
|
|
(col) => d[col.id] && d[col.id].length, |
|
|
|
d[col.id] = d[col.id].split(','); |
|
|
|
); |
|
|
|
} else { |
|
|
|
for (const col of availableUserColumns) { |
|
|
|
d[col.id] = null; |
|
|
|
d[col.id] = d[col.id].split(','); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (d[col.id]?.length) { |
|
|
|
d[col.id] = d[col.id].map((fid) => { |
|
|
|
d[col.id] = d[col.id].map((fid) => { |
|
|
|
const { id, email, display_name } = baseUsers.find( |
|
|
|
const { id, email, display_name } = baseUsers.find( |
|
|
|
(u) => u.id === fid, |
|
|
|
(u) => u.id === fid, |
|
|
|
); |
|
|
|
); |
|
|
|
return { |
|
|
|
return { |
|
|
|
id, |
|
|
|
id, |
|
|
|
email, |
|
|
|
email, |
|
|
|
display_name: display_name?.length ? display_name : null, |
|
|
|
display_name: display_name?.length ? display_name : null, |
|
|
|
}; |
|
|
|
}; |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// CreatedBy and LastModifiedBy are always singular
|
|
|
|
|
|
|
|
if ([UITypes.CreatedBy, UITypes.LastModifiedBy].includes(col.uidt)) { |
|
|
|
|
|
|
|
d[col.id] = d[col.id][0]; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -5130,13 +5212,15 @@ class BaseModelSqlv2 { |
|
|
|
raw: true, |
|
|
|
raw: true, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
await this.updateLastModifiedTime({ |
|
|
|
await this.updateLastModified({ |
|
|
|
model: parentTable, |
|
|
|
model: parentTable, |
|
|
|
rowIds: childIds, |
|
|
|
rowIds: childIds, |
|
|
|
|
|
|
|
cookie, |
|
|
|
}); |
|
|
|
}); |
|
|
|
await this.updateLastModifiedTime({ |
|
|
|
await this.updateLastModified({ |
|
|
|
model: childTable, |
|
|
|
model: childTable, |
|
|
|
rowIds: [rowId], |
|
|
|
rowIds: [rowId], |
|
|
|
|
|
|
|
cookie, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -5213,9 +5297,10 @@ class BaseModelSqlv2 { |
|
|
|
} |
|
|
|
} |
|
|
|
await this.execAndParse(updateQb, null, { raw: true }); |
|
|
|
await this.execAndParse(updateQb, null, { raw: true }); |
|
|
|
|
|
|
|
|
|
|
|
await this.updateLastModifiedTime({ |
|
|
|
await this.updateLastModified({ |
|
|
|
model: parentTable, |
|
|
|
model: parentTable, |
|
|
|
rowIds: [rowId], |
|
|
|
rowIds: [rowId], |
|
|
|
|
|
|
|
cookie, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -5260,9 +5345,10 @@ class BaseModelSqlv2 { |
|
|
|
{ raw: true }, |
|
|
|
{ raw: true }, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await this.updateLastModifiedTime({ |
|
|
|
await this.updateLastModified({ |
|
|
|
model: parentTable, |
|
|
|
model: parentTable, |
|
|
|
rowIds: [rowId], |
|
|
|
rowIds: [rowId], |
|
|
|
|
|
|
|
cookie, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -5406,13 +5492,15 @@ class BaseModelSqlv2 { |
|
|
|
); |
|
|
|
); |
|
|
|
await this.execAndParse(delQb, null, { raw: true }); |
|
|
|
await this.execAndParse(delQb, null, { raw: true }); |
|
|
|
|
|
|
|
|
|
|
|
await this.updateLastModifiedTime({ |
|
|
|
await this.updateLastModified({ |
|
|
|
model: parentTable, |
|
|
|
model: parentTable, |
|
|
|
rowIds: childIds, |
|
|
|
rowIds: childIds, |
|
|
|
|
|
|
|
cookie, |
|
|
|
}); |
|
|
|
}); |
|
|
|
await this.updateLastModifiedTime({ |
|
|
|
await this.updateLastModified({ |
|
|
|
model: childTable, |
|
|
|
model: childTable, |
|
|
|
rowIds: [rowId], |
|
|
|
rowIds: [rowId], |
|
|
|
|
|
|
|
cookie, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -5495,9 +5583,10 @@ class BaseModelSqlv2 { |
|
|
|
{ raw: true }, |
|
|
|
{ raw: true }, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await this.updateLastModifiedTime({ |
|
|
|
await this.updateLastModified({ |
|
|
|
model: parentTable, |
|
|
|
model: parentTable, |
|
|
|
rowIds: [rowId], |
|
|
|
rowIds: [rowId], |
|
|
|
|
|
|
|
cookie, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -5545,9 +5634,10 @@ class BaseModelSqlv2 { |
|
|
|
{ raw: true }, |
|
|
|
{ raw: true }, |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
await this.updateLastModifiedTime({ |
|
|
|
await this.updateLastModified({ |
|
|
|
model: parentTable, |
|
|
|
model: parentTable, |
|
|
|
rowIds: [childIds[0]], |
|
|
|
rowIds: [childIds[0]], |
|
|
|
|
|
|
|
cookie, |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
@ -5634,26 +5724,40 @@ class BaseModelSqlv2 { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async updateLastModifiedTime({ |
|
|
|
async updateLastModified({ |
|
|
|
rowIds, |
|
|
|
rowIds, |
|
|
|
|
|
|
|
cookie, |
|
|
|
model = this.model, |
|
|
|
model = this.model, |
|
|
|
knex = this.dbDriver, |
|
|
|
knex = this.dbDriver, |
|
|
|
}: { |
|
|
|
}: { |
|
|
|
rowIds: any | any[]; |
|
|
|
rowIds: any | any[]; |
|
|
|
|
|
|
|
cookie?: { user?: any }; |
|
|
|
model?: Model; |
|
|
|
model?: Model; |
|
|
|
knex?: XKnex; |
|
|
|
knex?: XKnex; |
|
|
|
}) { |
|
|
|
}) { |
|
|
|
const columnName = await model.getColumns().then((columns) => { |
|
|
|
const columns = await model.getColumns(); |
|
|
|
return columns.find( |
|
|
|
|
|
|
|
(c) => c.uidt === UITypes.LastModifiedTime && c.system, |
|
|
|
|
|
|
|
)?.column_name; |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!columnName) return; |
|
|
|
const updateObject = {}; |
|
|
|
|
|
|
|
|
|
|
|
const qb = knex(model.table_name).update({ |
|
|
|
const lastModifiedTimeColumn = columns.find( |
|
|
|
[columnName]: Noco.ncMeta.now(), |
|
|
|
(c) => c.uidt === UITypes.LastModifiedTime && c.system, |
|
|
|
}); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const lastModifiedByColumn = columns.find( |
|
|
|
|
|
|
|
(c) => c.uidt === UITypes.LastModifiedBy && c.system, |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (lastModifiedTimeColumn) { |
|
|
|
|
|
|
|
updateObject[lastModifiedTimeColumn.column_name] = Noco.ncMeta.now(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (lastModifiedByColumn) { |
|
|
|
|
|
|
|
updateObject[lastModifiedByColumn.column_name] = cookie?.user?.id; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Object.keys(updateObject).length === 0) return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const qb = knex(model.table_name).update(updateObject); |
|
|
|
|
|
|
|
|
|
|
|
for (const rowId of Array.isArray(rowIds) ? rowIds : [rowIds]) { |
|
|
|
for (const rowId of Array.isArray(rowIds) ? rowIds : [rowIds]) { |
|
|
|
qb.orWhere(await this._wherePk(rowId)); |
|
|
|
qb.orWhere(await this._wherePk(rowId)); |
|
|
@ -5662,7 +5766,7 @@ class BaseModelSqlv2 { |
|
|
|
await this.execAndParse(qb, null, { raw: true }); |
|
|
|
await this.execAndParse(qb, null, { raw: true }); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
async prepareNocoData(data, isInsertData = false) { |
|
|
|
async prepareNocoData(data, isInsertData = false, cookie?: { user?: any }) { |
|
|
|
if ( |
|
|
|
if ( |
|
|
|
this.model.columns.some((c) => |
|
|
|
this.model.columns.some((c) => |
|
|
|
[ |
|
|
|
[ |
|
|
@ -5670,19 +5774,25 @@ class BaseModelSqlv2 { |
|
|
|
UITypes.User, |
|
|
|
UITypes.User, |
|
|
|
UITypes.CreatedTime, |
|
|
|
UITypes.CreatedTime, |
|
|
|
UITypes.LastModifiedTime, |
|
|
|
UITypes.LastModifiedTime, |
|
|
|
|
|
|
|
UITypes.CreatedBy, |
|
|
|
|
|
|
|
UITypes.LastModifiedBy, |
|
|
|
].includes(c.uidt), |
|
|
|
].includes(c.uidt), |
|
|
|
) |
|
|
|
) |
|
|
|
) { |
|
|
|
) { |
|
|
|
for (const column of this.model.columns) { |
|
|
|
for (const column of this.model.columns) { |
|
|
|
if ( |
|
|
|
if (column.system) { |
|
|
|
isInsertData && |
|
|
|
if (isInsertData) { |
|
|
|
column.uidt === UITypes.CreatedTime && |
|
|
|
if (column.uidt === UITypes.CreatedTime) { |
|
|
|
column.system |
|
|
|
data[column.column_name] = Noco.ncMeta.now(); |
|
|
|
) { |
|
|
|
} else if (column.uidt === UITypes.CreatedBy) { |
|
|
|
data[column.column_name] = Noco.ncMeta.now(); |
|
|
|
data[column.column_name] = cookie?.user?.id; |
|
|
|
} |
|
|
|
} |
|
|
|
if (column.uidt === UITypes.LastModifiedTime && column.system) { |
|
|
|
} |
|
|
|
data[column.column_name] = isInsertData ? null : Noco.ncMeta.now(); |
|
|
|
if (column.uidt === UITypes.LastModifiedTime) { |
|
|
|
|
|
|
|
data[column.column_name] = isInsertData ? null : Noco.ncMeta.now(); |
|
|
|
|
|
|
|
} else if (column.uidt === UITypes.LastModifiedBy) { |
|
|
|
|
|
|
|
data[column.column_name] = isInsertData ? null : cookie?.user?.id; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if (column.uidt === UITypes.Attachment) { |
|
|
|
if (column.uidt === UITypes.Attachment) { |
|
|
|
if (data[column.column_name]) { |
|
|
|
if (data[column.column_name]) { |
|
|
@ -5699,7 +5809,11 @@ class BaseModelSqlv2 { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (column.uidt === UITypes.User) { |
|
|
|
} else if ( |
|
|
|
|
|
|
|
[UITypes.User, UITypes.CreatedBy, UITypes.LastModifiedBy].includes( |
|
|
|
|
|
|
|
column.uidt, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
) { |
|
|
|
if (data[column.column_name]) { |
|
|
|
if (data[column.column_name]) { |
|
|
|
const userIds = []; |
|
|
|
const userIds = []; |
|
|
|
|
|
|
|
|
|
|
|