|
|
@ -15,9 +15,13 @@ import { |
|
|
|
import { |
|
|
|
import { |
|
|
|
AuditOperationSubTypes, |
|
|
|
AuditOperationSubTypes, |
|
|
|
AuditOperationTypes, |
|
|
|
AuditOperationTypes, |
|
|
|
|
|
|
|
ColumnReqType, |
|
|
|
isVirtualCol, |
|
|
|
isVirtualCol, |
|
|
|
|
|
|
|
LinkToAnotherColumnReqType, |
|
|
|
LinkToAnotherRecordType, |
|
|
|
LinkToAnotherRecordType, |
|
|
|
|
|
|
|
LookupColumnReqType, |
|
|
|
RelationTypes, |
|
|
|
RelationTypes, |
|
|
|
|
|
|
|
RollupColumnReqType, |
|
|
|
substituteColumnAliasWithIdInFormula, |
|
|
|
substituteColumnAliasWithIdInFormula, |
|
|
|
substituteColumnIdWithAliasInFormula, |
|
|
|
substituteColumnIdWithAliasInFormula, |
|
|
|
TableType, |
|
|
|
TableType, |
|
|
@ -96,7 +100,10 @@ async function createHmAndBtColumn( |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export async function columnAdd(req: Request, res: Response<TableType>) { |
|
|
|
export async function columnAdd( |
|
|
|
|
|
|
|
req: Request<any, any, ColumnReqType & { uidt: UITypes }>, |
|
|
|
|
|
|
|
res: Response<TableType> |
|
|
|
|
|
|
|
) { |
|
|
|
const table = await Model.getWithInfo({ |
|
|
|
const table = await Model.getWithInfo({ |
|
|
|
id: req.params.tableId, |
|
|
|
id: req.params.tableId, |
|
|
|
}); |
|
|
|
}); |
|
|
@ -121,7 +128,7 @@ export async function columnAdd(req: Request, res: Response<TableType>) { |
|
|
|
NcError.badRequest('Duplicate column alias'); |
|
|
|
NcError.badRequest('Duplicate column alias'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
let colBody = req.body; |
|
|
|
let colBody: any = req.body; |
|
|
|
switch (colBody.uidt) { |
|
|
|
switch (colBody.uidt) { |
|
|
|
case UITypes.Rollup: |
|
|
|
case UITypes.Rollup: |
|
|
|
{ |
|
|
|
{ |
|
|
@ -137,7 +144,7 @@ export async function columnAdd(req: Request, res: Response<TableType>) { |
|
|
|
|
|
|
|
|
|
|
|
const relation = await ( |
|
|
|
const relation = await ( |
|
|
|
await Column.get({ |
|
|
|
await Column.get({ |
|
|
|
colId: req.body.fk_relation_column_id, |
|
|
|
colId: (req.body as RollupColumnReqType).fk_relation_column_id, |
|
|
|
}) |
|
|
|
}) |
|
|
|
).getColOptions<LinkToAnotherRecordType>(); |
|
|
|
).getColOptions<LinkToAnotherRecordType>(); |
|
|
|
|
|
|
|
|
|
|
@ -163,7 +170,8 @@ export async function columnAdd(req: Request, res: Response<TableType>) { |
|
|
|
const relatedTable = await relatedColumn.getModel(); |
|
|
|
const relatedTable = await relatedColumn.getModel(); |
|
|
|
if ( |
|
|
|
if ( |
|
|
|
!(await relatedTable.getColumns()).find( |
|
|
|
!(await relatedTable.getColumns()).find( |
|
|
|
(c) => c.id === req.body.fk_rollup_column_id |
|
|
|
(c) => |
|
|
|
|
|
|
|
c.id === (req.body as RollupColumnReqType).fk_rollup_column_id |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
throw new Error('Rollup column not found in related table'); |
|
|
|
throw new Error('Rollup column not found in related table'); |
|
|
@ -183,7 +191,7 @@ export async function columnAdd(req: Request, res: Response<TableType>) { |
|
|
|
|
|
|
|
|
|
|
|
const relation = await ( |
|
|
|
const relation = await ( |
|
|
|
await Column.get({ |
|
|
|
await Column.get({ |
|
|
|
colId: req.body.fk_relation_column_id, |
|
|
|
colId: (req.body as LookupColumnReqType).fk_relation_column_id, |
|
|
|
}) |
|
|
|
}) |
|
|
|
).getColOptions<LinkToAnotherRecordType>(); |
|
|
|
).getColOptions<LinkToAnotherRecordType>(); |
|
|
|
|
|
|
|
|
|
|
@ -209,7 +217,8 @@ export async function columnAdd(req: Request, res: Response<TableType>) { |
|
|
|
const relatedTable = await relatedColumn.getModel(); |
|
|
|
const relatedTable = await relatedColumn.getModel(); |
|
|
|
if ( |
|
|
|
if ( |
|
|
|
!(await relatedTable.getColumns()).find( |
|
|
|
!(await relatedTable.getColumns()).find( |
|
|
|
(c) => c.id === req.body.fk_lookup_column_id |
|
|
|
(c) => |
|
|
|
|
|
|
|
c.id === (req.body as LookupColumnReqType).fk_lookup_column_id |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
) |
|
|
|
throw new Error('Lookup column not found in related table'); |
|
|
|
throw new Error('Lookup column not found in related table'); |
|
|
@ -227,14 +236,21 @@ export async function columnAdd(req: Request, res: Response<TableType>) { |
|
|
|
validateParams(['parentId', 'childId', 'type'], req.body); |
|
|
|
validateParams(['parentId', 'childId', 'type'], req.body); |
|
|
|
|
|
|
|
|
|
|
|
// get parent and child models
|
|
|
|
// get parent and child models
|
|
|
|
const parent = await Model.getWithInfo({ id: req.body.parentId }); |
|
|
|
const parent = await Model.getWithInfo({ |
|
|
|
const child = await Model.getWithInfo({ id: req.body.childId }); |
|
|
|
id: (req.body as LinkToAnotherColumnReqType).parentId, |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
const child = await Model.getWithInfo({ |
|
|
|
|
|
|
|
id: (req.body as LinkToAnotherColumnReqType).childId, |
|
|
|
|
|
|
|
}); |
|
|
|
let childColumn: Column; |
|
|
|
let childColumn: Column; |
|
|
|
|
|
|
|
|
|
|
|
const sqlMgr = await ProjectMgrv2.getSqlMgr({ |
|
|
|
const sqlMgr = await ProjectMgrv2.getSqlMgr({ |
|
|
|
id: base.project_id, |
|
|
|
id: base.project_id, |
|
|
|
}); |
|
|
|
}); |
|
|
|
if (req.body.type === 'hm' || req.body.type === 'bt') { |
|
|
|
if ( |
|
|
|
|
|
|
|
(req.body as LinkToAnotherColumnReqType).type === 'hm' || |
|
|
|
|
|
|
|
(req.body as LinkToAnotherColumnReqType).type === 'bt' |
|
|
|
|
|
|
|
) { |
|
|
|
// populate fk column name
|
|
|
|
// populate fk column name
|
|
|
|
const fkColName = getUniqueColumnName( |
|
|
|
const fkColName = getUniqueColumnName( |
|
|
|
await child.getColumns(), |
|
|
|
await child.getColumns(), |
|
|
@ -285,7 +301,7 @@ export async function columnAdd(req: Request, res: Response<TableType>) { |
|
|
|
childColumn = await Column.get({ colId: id }); |
|
|
|
childColumn = await Column.get({ colId: id }); |
|
|
|
|
|
|
|
|
|
|
|
// ignore relation creation if virtual
|
|
|
|
// ignore relation creation if virtual
|
|
|
|
if (!req.body.virtual) { |
|
|
|
if (!(req.body as LinkToAnotherColumnReqType).virtual) { |
|
|
|
// create relation
|
|
|
|
// create relation
|
|
|
|
await sqlMgr.sqlOpPlus(base, 'relationCreate', { |
|
|
|
await sqlMgr.sqlOpPlus(base, 'relationCreate', { |
|
|
|
childColumn: fkColName, |
|
|
|
childColumn: fkColName, |
|
|
@ -315,11 +331,11 @@ export async function columnAdd(req: Request, res: Response<TableType>) { |
|
|
|
child, |
|
|
|
child, |
|
|
|
parent, |
|
|
|
parent, |
|
|
|
childColumn, |
|
|
|
childColumn, |
|
|
|
req.body.type, |
|
|
|
(req.body as LinkToAnotherColumnReqType).type as RelationTypes, |
|
|
|
req.body.title, |
|
|
|
(req.body as LinkToAnotherColumnReqType).title, |
|
|
|
req.body.virtual |
|
|
|
(req.body as LinkToAnotherColumnReqType).virtual |
|
|
|
); |
|
|
|
); |
|
|
|
} else if (req.body.type === 'mm') { |
|
|
|
} else if ((req.body as LinkToAnotherColumnReqType).type === 'mm') { |
|
|
|
const aTn = `${project?.prefix ?? ''}_nc_m2m_${randomID()}`; |
|
|
|
const aTn = `${project?.prefix ?? ''}_nc_m2m_${randomID()}`; |
|
|
|
const aTnAlias = aTn; |
|
|
|
const aTnAlias = aTn; |
|
|
|
|
|
|
|
|
|
|
@ -378,7 +394,7 @@ export async function columnAdd(req: Request, res: Response<TableType>) { |
|
|
|
columns: associateTableCols, |
|
|
|
columns: associateTableCols, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
if (!req.body.virtual) { |
|
|
|
if (!(req.body as LinkToAnotherColumnReqType).virtual) { |
|
|
|
const rel1Args = { |
|
|
|
const rel1Args = { |
|
|
|
...req.body, |
|
|
|
...req.body, |
|
|
|
childTable: aTn, |
|
|
|
childTable: aTn, |
|
|
@ -412,7 +428,7 @@ export async function columnAdd(req: Request, res: Response<TableType>) { |
|
|
|
childCol, |
|
|
|
childCol, |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
req.body.virtual, |
|
|
|
(req.body as LinkToAnotherColumnReqType).virtual, |
|
|
|
true |
|
|
|
true |
|
|
|
); |
|
|
|
); |
|
|
|
await createHmAndBtColumn( |
|
|
|
await createHmAndBtColumn( |
|
|
@ -421,7 +437,7 @@ export async function columnAdd(req: Request, res: Response<TableType>) { |
|
|
|
parentCol, |
|
|
|
parentCol, |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
null, |
|
|
|
req.body.virtual, |
|
|
|
(req.body as LinkToAnotherColumnReqType).virtual, |
|
|
|
true |
|
|
|
true |
|
|
|
); |
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|