Browse Source

feat: OldData - dataUpdate

pull/5444/head
Wing-Kam Wong 2 years ago committed by Pranav C
parent
commit
eb2a0d4733
  1. 19
      packages/nocodb-nest/src/modules/datas/old-datas/old-datas.controller.ts
  2. 23
      packages/nocodb-nest/src/modules/datas/old-datas/old-datas.service.ts

19
packages/nocodb-nest/src/modules/datas/old-datas/old-datas.controller.ts

@ -50,4 +50,23 @@ export class OldDatasController {
async dataRead(@Request() req, @Response() res) { async dataRead(@Request() req, @Response() res) {
res.json(await this.oldDatasService.dataRead(req)); res.json(await this.oldDatasService.dataRead(req));
} }
@Patch('/nc/:projectId/api/v1/:tableName/:rowId')
@Acl('dataUpdate')
async dataUpdate(
@Request() req,
@Response() res,
@Param('projectId') projectId: string,
@Param('tableName') tableName: string,
@Param('rowId') rowId: string,
) {
res.json(
await this.oldDatasService.dataUpdate({
projectId: projectId,
tableName: tableName,
body: req.body,
rowId,
}),
);
}
} }

23
packages/nocodb-nest/src/modules/datas/old-datas/old-datas.service.ts

@ -1,5 +1,5 @@
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { getViewAndModelByAliasOrId, PathParams } from '../helpers'; import { getViewAndModelByAliasOrId, OldPathParams } from '../helpers';
import getAst from '../../../helpers/getAst'; import getAst from '../../../helpers/getAst';
import { NcError } from '../../../helpers/catchError'; import { NcError } from '../../../helpers/catchError';
import { import {
@ -16,7 +16,7 @@ import { nocoExecute } from 'nc-help';
@Injectable() @Injectable()
export class OldDatasService { export class OldDatasService {
async getDataList(param: PathParams & { query: any }) { async getDataList(param: OldPathParams & { query: any }) {
const { model, view } = await this.getViewAndModelFromRequest(param); const { model, view } = await this.getViewAndModelFromRequest(param);
const base = await Base.get(model.base_id); const base = await Base.get(model.base_id);
@ -43,7 +43,7 @@ export class OldDatasService {
return await nocoExecute(ast, await baseModel.list(listArgs), {}, listArgs); return await nocoExecute(ast, await baseModel.list(listArgs), {}, listArgs);
} }
async getDataCount(param: PathParams & { query: any }) { async getDataCount(param: OldPathParams & { query: any }) {
const { model, view } = await this.getViewAndModelFromRequest(param); const { model, view } = await this.getViewAndModelFromRequest(param);
const base = await Base.get(model.base_id); const base = await Base.get(model.base_id);
@ -61,7 +61,7 @@ export class OldDatasService {
return await baseModel.count(listArgs); return await baseModel.count(listArgs);
} }
async dataInsert(param: PathParams & { body: unknown }) { async dataInsert(param: OldPathParams & { body: unknown }) {
const { model, view } = await this.getViewAndModelFromRequest(param); const { model, view } = await this.getViewAndModelFromRequest(param);
const base = await Base.get(model.base_id); const base = await Base.get(model.base_id);
@ -75,7 +75,7 @@ export class OldDatasService {
return await baseModel.insert(param.body, null, param); return await baseModel.insert(param.body, null, param);
} }
async dataRead(param: PathParams & { query: any; rowId: string }) { async dataRead(param: OldPathParams & { query: any; rowId: string }) {
const { model, view } = await this.getViewAndModelFromRequest(param); const { model, view } = await this.getViewAndModelFromRequest(param);
const base = await Base.get(model.base_id); const base = await Base.get(model.base_id);
@ -100,6 +100,19 @@ export class OldDatasService {
); );
} }
async dataUpdate(param: OldPathParams & { body: unknown; rowId: string }) {
const { model, view } = await this.getViewAndModelFromRequest(param);
const base = await Base.get(model.base_id);
const baseModel = await Model.getBaseModelSQL({
id: model.id,
viewId: view.id,
dbDriver: await NcConnectionMgrv2.get(base),
});
return await baseModel.updateByPk(param.rowId, param.body, null, param);
}
async getViewAndModelFromRequest(req) { async getViewAndModelFromRequest(req) {
const project = await Project.getWithInfo(req.params.projectId); const project = await Project.getWithInfo(req.params.projectId);
const model = await Model.getByAliasOrId({ const model = await Model.getByAliasOrId({

Loading…
Cancel
Save