|
|
@ -3384,36 +3384,56 @@ export default class NcMetaMgr { |
|
|
|
condition: { |
|
|
|
condition: { |
|
|
|
model_name: args.args.model_name |
|
|
|
model_name: args.args.model_name |
|
|
|
}, |
|
|
|
}, |
|
|
|
fields: ['id', 'view_id', 'password', 'model_name', 'view_type'] |
|
|
|
fields: [ |
|
|
|
|
|
|
|
'id', |
|
|
|
|
|
|
|
'view_id', |
|
|
|
|
|
|
|
'password', |
|
|
|
|
|
|
|
'model_name', |
|
|
|
|
|
|
|
'view_type', |
|
|
|
|
|
|
|
'view_name' |
|
|
|
|
|
|
|
] |
|
|
|
} |
|
|
|
} |
|
|
|
); |
|
|
|
); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected async getSharedViewData(req, args: any): Promise<any> { |
|
|
|
protected async getSharedViewData(req, args: any): Promise<any> { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const viewMeta = await this.xcMeta |
|
|
|
const sharedViewMeta = await this.xcMeta |
|
|
|
.knex('nc_shared_views') |
|
|
|
.knex('nc_shared_views') |
|
|
|
.where({ |
|
|
|
.where({ |
|
|
|
view_id: args.args.view_id |
|
|
|
view_id: args.args.view_id |
|
|
|
}) |
|
|
|
}) |
|
|
|
.first(); |
|
|
|
.first(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!sharedViewMeta) { |
|
|
|
|
|
|
|
throw new Error('Meta not found'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const viewMeta = await this.xcMeta.metaGet( |
|
|
|
|
|
|
|
sharedViewMeta.project_id, |
|
|
|
|
|
|
|
sharedViewMeta.db_alias, |
|
|
|
|
|
|
|
'nc_models', |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
title: sharedViewMeta.view_name |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
// if (viewMeta && viewMeta.password && viewMeta.password !== args.args.password) {
|
|
|
|
// if (viewMeta && viewMeta.password && viewMeta.password !== args.args.password) {
|
|
|
|
// throw new Error('Invalid password')
|
|
|
|
// throw new Error('Invalid password')
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
if ( |
|
|
|
viewMeta && |
|
|
|
sharedViewMeta && |
|
|
|
viewMeta.password && |
|
|
|
sharedViewMeta.password && |
|
|
|
viewMeta.password !== args.args.password |
|
|
|
sharedViewMeta.password !== args.args.password |
|
|
|
) { |
|
|
|
) { |
|
|
|
throw new Error(this.INVALID_PASSWORD_ERROR); |
|
|
|
throw new Error(this.INVALID_PASSWORD_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const apiBuilder = this.app?.projectBuilders |
|
|
|
const apiBuilder = this.app?.projectBuilders |
|
|
|
?.find(pb => pb.id === viewMeta.project_id) |
|
|
|
?.find(pb => pb.id === sharedViewMeta.project_id) |
|
|
|
?.apiBuilders?.find(ab => ab.dbAlias === viewMeta.db_alias); |
|
|
|
?.apiBuilders?.find(ab => ab.dbAlias === sharedViewMeta.db_alias); |
|
|
|
const model = apiBuilder?.xcModels?.[viewMeta.model_name]; |
|
|
|
const model = apiBuilder?.xcModels?.[sharedViewMeta.model_name]; |
|
|
|
|
|
|
|
|
|
|
|
if (model) { |
|
|
|
if (model) { |
|
|
|
const queryParams = JSON.parse(viewMeta.query_params); |
|
|
|
const queryParams = JSON.parse(viewMeta.query_params); |
|
|
@ -3430,8 +3450,8 @@ export default class NcMetaMgr { |
|
|
|
const fields = queryParams?.fields || '*'; |
|
|
|
const fields = queryParams?.fields || '*'; |
|
|
|
|
|
|
|
|
|
|
|
return { |
|
|
|
return { |
|
|
|
model_name: viewMeta.model_name, |
|
|
|
model_name: sharedViewMeta.model_name, |
|
|
|
meta: apiBuilder?.getMeta(viewMeta.model_name), //JSON.parse(viewMeta.meta),
|
|
|
|
meta: apiBuilder?.getMeta(sharedViewMeta.model_name), //JSON.parse(viewMeta.meta),
|
|
|
|
data: await model.list({ |
|
|
|
data: await model.list({ |
|
|
|
...req.query, |
|
|
|
...req.query, |
|
|
|
where, |
|
|
|
where, |
|
|
@ -3452,21 +3472,34 @@ export default class NcMetaMgr { |
|
|
|
|
|
|
|
|
|
|
|
protected async sharedViewNestedDataGet(_req, args: any): Promise<any> { |
|
|
|
protected async sharedViewNestedDataGet(_req, args: any): Promise<any> { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const viewMeta = await this.xcMeta |
|
|
|
const sharedViewMeta = await this.xcMeta |
|
|
|
.knex('nc_shared_views') |
|
|
|
.knex('nc_shared_views') |
|
|
|
.where({ |
|
|
|
.where({ |
|
|
|
view_id: args.args.view_id |
|
|
|
view_id: args.args.view_id |
|
|
|
}) |
|
|
|
}) |
|
|
|
.first(); |
|
|
|
.first(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!sharedViewMeta) { |
|
|
|
|
|
|
|
throw new Error('Meta not found'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const viewMeta = await this.xcMeta.metaGet( |
|
|
|
|
|
|
|
sharedViewMeta.project_id, |
|
|
|
|
|
|
|
sharedViewMeta.db_alias, |
|
|
|
|
|
|
|
'nc_models', |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
title: sharedViewMeta.view_name |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (!viewMeta) { |
|
|
|
if (!viewMeta) { |
|
|
|
throw new Error('Not found'); |
|
|
|
throw new Error('Not found'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
if ( |
|
|
|
viewMeta && |
|
|
|
sharedViewMeta && |
|
|
|
viewMeta.password && |
|
|
|
sharedViewMeta.password && |
|
|
|
viewMeta.password !== args.args.password |
|
|
|
sharedViewMeta.password !== args.args.password |
|
|
|
) { |
|
|
|
) { |
|
|
|
throw new Error(this.INVALID_PASSWORD_ERROR); |
|
|
|
throw new Error(this.INVALID_PASSWORD_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
@ -3477,8 +3510,8 @@ export default class NcMetaMgr { |
|
|
|
// const queryParams = JSON.parse(viewMeta.query_params);
|
|
|
|
// const queryParams = JSON.parse(viewMeta.query_params);
|
|
|
|
|
|
|
|
|
|
|
|
const apiBuilder = this.app?.projectBuilders |
|
|
|
const apiBuilder = this.app?.projectBuilders |
|
|
|
?.find(pb => pb.id === viewMeta.project_id) |
|
|
|
?.find(pb => pb.id === sharedViewMeta.project_id) |
|
|
|
?.apiBuilders?.find(ab => ab.dbAlias === viewMeta.db_alias); |
|
|
|
?.apiBuilders?.find(ab => ab.dbAlias === sharedViewMeta.db_alias); |
|
|
|
|
|
|
|
|
|
|
|
// todo: only allow related table
|
|
|
|
// todo: only allow related table
|
|
|
|
// if(tn &&){
|
|
|
|
// if(tn &&){
|
|
|
@ -3517,21 +3550,36 @@ export default class NcMetaMgr { |
|
|
|
|
|
|
|
|
|
|
|
protected async sharedViewNestedChildDataGet(_req, args: any): Promise<any> { |
|
|
|
protected async sharedViewNestedChildDataGet(_req, args: any): Promise<any> { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const viewMeta = await this.xcMeta |
|
|
|
// todo: replace with join query
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const sharedViewMeta = await this.xcMeta |
|
|
|
.knex('nc_shared_views') |
|
|
|
.knex('nc_shared_views') |
|
|
|
.where({ |
|
|
|
.where({ |
|
|
|
view_id: args.args.view_id |
|
|
|
view_id: args.args.view_id |
|
|
|
}) |
|
|
|
}) |
|
|
|
.first(); |
|
|
|
.first(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!sharedViewMeta) { |
|
|
|
|
|
|
|
throw new Error('Meta not found'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const viewMeta = await this.xcMeta.metaGet( |
|
|
|
|
|
|
|
sharedViewMeta.project_id, |
|
|
|
|
|
|
|
sharedViewMeta.db_alias, |
|
|
|
|
|
|
|
'nc_models', |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
title: sharedViewMeta.view_name |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (!viewMeta) { |
|
|
|
if (!viewMeta) { |
|
|
|
throw new Error('Not found'); |
|
|
|
throw new Error('Not found'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
if ( |
|
|
|
viewMeta && |
|
|
|
sharedViewMeta && |
|
|
|
viewMeta.password && |
|
|
|
sharedViewMeta.password && |
|
|
|
viewMeta.password !== args.args.password |
|
|
|
sharedViewMeta.password !== args.args.password |
|
|
|
) { |
|
|
|
) { |
|
|
|
throw new Error(this.INVALID_PASSWORD_ERROR); |
|
|
|
throw new Error(this.INVALID_PASSWORD_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
@ -3547,8 +3595,8 @@ export default class NcMetaMgr { |
|
|
|
// const queryParams = JSON.parse(viewMeta.query_params);
|
|
|
|
// const queryParams = JSON.parse(viewMeta.query_params);
|
|
|
|
|
|
|
|
|
|
|
|
const apiBuilder = this.app?.projectBuilders |
|
|
|
const apiBuilder = this.app?.projectBuilders |
|
|
|
?.find(pb => pb.id === viewMeta.project_id) |
|
|
|
?.find(pb => pb.id === sharedViewMeta.project_id) |
|
|
|
?.apiBuilders?.find(ab => ab.dbAlias === viewMeta.db_alias); |
|
|
|
?.apiBuilders?.find(ab => ab.dbAlias === sharedViewMeta.db_alias); |
|
|
|
|
|
|
|
|
|
|
|
const model = apiBuilder.xcModels?.[tn]; |
|
|
|
const model = apiBuilder.xcModels?.[tn]; |
|
|
|
const parentMeta = apiBuilder.getMeta(ptn); |
|
|
|
const parentMeta = apiBuilder.getMeta(ptn); |
|
|
@ -3617,21 +3665,33 @@ export default class NcMetaMgr { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected async sharedViewInsert(req, args: any): Promise<any> { |
|
|
|
protected async sharedViewInsert(req, args: any): Promise<any> { |
|
|
|
const viewMeta = await this.xcMeta |
|
|
|
const sharedViewMeta = await this.xcMeta |
|
|
|
.knex('nc_shared_views') |
|
|
|
.knex('nc_shared_views') |
|
|
|
.where({ |
|
|
|
.where({ |
|
|
|
view_id: args.args.view_id |
|
|
|
view_id: args.args.view_id |
|
|
|
}) |
|
|
|
}) |
|
|
|
.first(); |
|
|
|
.first(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!sharedViewMeta) { |
|
|
|
|
|
|
|
throw new Error('Meta not found'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const viewMeta = await this.xcMeta.metaGet( |
|
|
|
|
|
|
|
sharedViewMeta.project_id, |
|
|
|
|
|
|
|
sharedViewMeta.db_alias, |
|
|
|
|
|
|
|
'nc_models', |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
title: sharedViewMeta.view_name |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
if (!viewMeta) { |
|
|
|
if (!viewMeta) { |
|
|
|
throw new Error('Not found'); |
|
|
|
throw new Error('Not found'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
if ( |
|
|
|
viewMeta && |
|
|
|
sharedViewMeta && |
|
|
|
viewMeta.password && |
|
|
|
sharedViewMeta.password && |
|
|
|
viewMeta.password !== args.args.password |
|
|
|
sharedViewMeta.password !== args.args.password |
|
|
|
) { |
|
|
|
) { |
|
|
|
throw new Error(this.INVALID_PASSWORD_ERROR); |
|
|
|
throw new Error(this.INVALID_PASSWORD_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
@ -3642,8 +3702,8 @@ export default class NcMetaMgr { |
|
|
|
const fields: string[] = queryParams?.fields.split(','); |
|
|
|
const fields: string[] = queryParams?.fields.split(','); |
|
|
|
|
|
|
|
|
|
|
|
const apiBuilder = this.app?.projectBuilders |
|
|
|
const apiBuilder = this.app?.projectBuilders |
|
|
|
?.find(pb => pb.id === viewMeta.project_id) |
|
|
|
?.find(pb => pb.id === sharedViewMeta.project_id) |
|
|
|
?.apiBuilders?.find(ab => ab.dbAlias === viewMeta.db_alias); |
|
|
|
?.apiBuilders?.find(ab => ab.dbAlias === sharedViewMeta.db_alias); |
|
|
|
|
|
|
|
|
|
|
|
const insertObject = Object.entries(args.args.data).reduce( |
|
|
|
const insertObject = Object.entries(args.args.data).reduce( |
|
|
|
(obj, [key, val]) => { |
|
|
|
(obj, [key, val]) => { |
|
|
@ -3661,7 +3721,7 @@ export default class NcMetaMgr { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const model = apiBuilder?.xcModels?.[viewMeta.model_name]; |
|
|
|
const model = apiBuilder?.xcModels?.[sharedViewMeta.model_name]; |
|
|
|
if (model) { |
|
|
|
if (model) { |
|
|
|
req.query.form = viewMeta.view_name; |
|
|
|
req.query.form = viewMeta.view_name; |
|
|
|
await model.nestedInsert(insertObject, null, req); |
|
|
|
await model.nestedInsert(insertObject, null, req); |
|
|
@ -3669,21 +3729,34 @@ export default class NcMetaMgr { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected async sharedViewGet(_req, args: any): Promise<any> { |
|
|
|
protected async sharedViewGet(_req, args: any): Promise<any> { |
|
|
|
const viewMeta = await this.xcMeta |
|
|
|
const sharedViewMeta = await this.xcMeta |
|
|
|
.knex('nc_shared_views') |
|
|
|
.knex('nc_shared_views') |
|
|
|
.where({ |
|
|
|
.where({ |
|
|
|
view_id: args.args.view_id |
|
|
|
view_id: args.args.view_id |
|
|
|
}) |
|
|
|
}) |
|
|
|
.first(); |
|
|
|
.first(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!sharedViewMeta) { |
|
|
|
|
|
|
|
throw new Error('Meta not found'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const viewMeta = await this.xcMeta.metaGet( |
|
|
|
|
|
|
|
sharedViewMeta.project_id, |
|
|
|
|
|
|
|
sharedViewMeta.db_alias, |
|
|
|
|
|
|
|
'nc_models', |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
title: sharedViewMeta.view_name |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
if (!viewMeta) { |
|
|
|
if (!viewMeta) { |
|
|
|
throw new Error('Not found'); |
|
|
|
throw new Error('Not found'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ( |
|
|
|
if ( |
|
|
|
viewMeta && |
|
|
|
sharedViewMeta && |
|
|
|
viewMeta.password && |
|
|
|
sharedViewMeta.password && |
|
|
|
viewMeta.password !== args.args.password |
|
|
|
sharedViewMeta.password !== args.args.password |
|
|
|
) { |
|
|
|
) { |
|
|
|
throw new Error(this.INVALID_PASSWORD_ERROR); |
|
|
|
throw new Error(this.INVALID_PASSWORD_ERROR); |
|
|
|
} |
|
|
|
} |
|
|
@ -3691,11 +3764,11 @@ export default class NcMetaMgr { |
|
|
|
// todo : filter out columns of related table
|
|
|
|
// todo : filter out columns of related table
|
|
|
|
try { |
|
|
|
try { |
|
|
|
const apiBuilder = this.app?.projectBuilders |
|
|
|
const apiBuilder = this.app?.projectBuilders |
|
|
|
?.find(pb => pb.id === viewMeta.project_id) |
|
|
|
?.find(pb => pb.id === sharedViewMeta.project_id) |
|
|
|
?.apiBuilders?.find(ab => ab.dbAlias === viewMeta.db_alias); |
|
|
|
?.apiBuilders?.find(ab => ab.dbAlias === sharedViewMeta.db_alias); |
|
|
|
|
|
|
|
|
|
|
|
const tableMeta = (viewMeta.meta = apiBuilder?.getMeta( |
|
|
|
const tableMeta = (viewMeta.meta = apiBuilder?.getMeta( |
|
|
|
viewMeta.model_name |
|
|
|
sharedViewMeta.model_name |
|
|
|
)); |
|
|
|
)); |
|
|
|
|
|
|
|
|
|
|
|
const relatedTableMetas = {}; |
|
|
|
const relatedTableMetas = {}; |
|
|
|