Browse Source

refactor: suggested changes

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/5239/head
Pranav C 2 years ago
parent
commit
c0ad5b1d1a
  1. 8
      packages/nocodb/src/lib/controllers/auditController.ts
  2. 5
      packages/nocodb/src/lib/controllers/dataControllers/bulkDataAliasController.ts
  3. 2
      packages/nocodb/src/lib/controllers/dataControllers/dataAliasController.ts
  4. 2
      packages/nocodb/src/lib/controllers/dataControllers/dataAliasExportController.ts
  5. 14
      packages/nocodb/src/lib/controllers/userController/userApis.ts
  6. 8
      packages/nocodb/src/lib/meta/api/index.ts
  7. 5
      packages/nocodb/src/lib/services/attachmentService.ts
  8. 14
      packages/nocodb/src/lib/services/auditService.ts
  9. 6
      packages/nocodb/src/lib/services/dataService/export.ts
  10. 5
      packages/nocodb/src/lib/services/projectUserService.ts
  11. 6
      packages/nocodb/src/lib/services/syncService/helpers/job.ts
  12. 3
      packages/nocodb/src/lib/services/tableService.ts

8
packages/nocodb/src/lib/controllers/auditController.ts

@ -9,9 +9,7 @@ export async function commentRow(req: Request<any, any>, res) {
await auditService.commentRow({ await auditService.commentRow({
rowId: req.params.rowId, rowId: req.params.rowId,
user: (req as any).user, user: (req as any).user,
body: { body: req.body,
...req.body,
},
}) })
); );
} }
@ -20,9 +18,7 @@ export async function auditRowUpdate(req: Request<any, any>, res) {
res.json( res.json(
await auditService.auditRowUpdate({ await auditService.auditRowUpdate({
rowId: req.params.rowId, rowId: req.params.rowId,
body: { body: req.body,
...req.body,
},
}) })
); );
} }

5
packages/nocodb/src/lib/controllers/dataControllers/bulkDataAliasController.ts

@ -1,10 +1,8 @@
import { Request, Response, Router } from 'express'; import { Request, Response, Router } from 'express';
import { bulkDataService } from '../../services' import { bulkDataService } from '../../services';
import ncMetaAclMw from '../../meta/helpers/ncMetaAclMw'; import ncMetaAclMw from '../../meta/helpers/ncMetaAclMw';
import apiMetrics from '../../meta/helpers/apiMetrics'; import apiMetrics from '../../meta/helpers/apiMetrics';
async function bulkDataInsert(req: Request, res: Response) { async function bulkDataInsert(req: Request, res: Response) {
res.json( res.json(
await bulkDataService.bulkDataInsert({ await bulkDataService.bulkDataInsert({
@ -63,7 +61,6 @@ async function bulkDataDeleteAll(req: Request, res: Response) {
); );
} }
const router = Router({ mergeParams: true }); const router = Router({ mergeParams: true });
router.post( router.post(

2
packages/nocodb/src/lib/controllers/dataControllers/dataAliasController.ts

@ -1,5 +1,5 @@
import { Request, Response, Router } from 'express'; import { Request, Response, Router } from 'express';
import { dataService } from '../../services' import { dataService } from '../../services';
import ncMetaAclMw from '../../meta/helpers/ncMetaAclMw'; import ncMetaAclMw from '../../meta/helpers/ncMetaAclMw';
import apiMetrics from '../../meta/helpers/apiMetrics'; import apiMetrics from '../../meta/helpers/apiMetrics';
import { parseHrtimeToSeconds } from '../../meta/api/helpers'; import { parseHrtimeToSeconds } from '../../meta/api/helpers';

2
packages/nocodb/src/lib/controllers/dataControllers/dataAliasExportController.ts

@ -7,7 +7,7 @@ import {
extractCsvData, extractCsvData,
extractXlsxData, extractXlsxData,
} from '../../services/dataService/helpers'; } from '../../services/dataService/helpers';
import { getViewAndModelFromRequestByAliasOrId } from './helpers' import { getViewAndModelFromRequestByAliasOrId } from './helpers';
async function excelDataExport(req: Request, res: Response) { async function excelDataExport(req: Request, res: Response) {
const { model, view } = await getViewAndModelFromRequestByAliasOrId(req); const { model, view } = await getViewAndModelFromRequestByAliasOrId(req);

14
packages/nocodb/src/lib/controllers/userController/userApis.ts

@ -137,13 +137,13 @@ export async function signup(req: Request, res: Response<TableType>) {
} }
async function successfulSignIn({ async function successfulSignIn({
user, user,
err, err,
info, info,
req, req,
res, res,
auditDescription, auditDescription,
}) { }) {
try { try {
if (!user || !user.email) { if (!user || !user.email) {
if (err) { if (err) {

8
packages/nocodb/src/lib/meta/api/index.ts

@ -1,4 +1,4 @@
import { Tele } from 'nc-help'; import { T } from 'nc-help';
import orgLicenseController from '../../controllers/orgLicenseController'; import orgLicenseController from '../../controllers/orgLicenseController';
import orgTokenController from '../../controllers/orgTokenController'; import orgTokenController from '../../controllers/orgTokenController';
import orgUserController from '../../controllers/orgUserController'; import orgUserController from '../../controllers/orgUserController';
@ -133,15 +133,15 @@ export default function (router: Router, server) {
}).on('connection', (socket) => { }).on('connection', (socket) => {
clients[socket.id] = socket; clients[socket.id] = socket;
const id = getHash( const id = getHash(
(process.env.NC_SERVER_UUID || Tele.id) + (process.env.NC_SERVER_UUID || T.id) +
(socket?.handshake as any)?.user?.id (socket?.handshake as any)?.user?.id
); );
socket.on('page', (args) => { socket.on('page', (args) => {
Tele.page({ ...args, id }); T.page({ ...args, id });
}); });
socket.on('event', (args) => { socket.on('event', (args) => {
Tele.event({ ...args, id }); T.event({ ...args, id });
}); });
socket.on('subscribe', (room) => { socket.on('subscribe', (room) => {
if (room in jobs) { if (room in jobs) {

5
packages/nocodb/src/lib/services/attachmentService.ts

@ -1,8 +1,3 @@
// @ts-ignore
import { Request, Response, Router } from 'express';
import { nanoid } from 'nanoid'; import { nanoid } from 'nanoid';
import path from 'path'; import path from 'path';
import slash from 'slash'; import slash from 'slash';

14
packages/nocodb/src/lib/services/auditService.ts

@ -1,10 +1,10 @@
import {
AuditRowUpdatePayloadType,
CommentRowPayloadType,
} from 'nocodb-sdk/build/main/lib/CustomAPI';
import { validatePayload } from '../meta/api/helpers'; import { validatePayload } from '../meta/api/helpers';
import Audit from '../models/Audit'; import Audit from '../models/Audit';
import { AuditOperationSubTypes, AuditOperationTypes } from 'nocodb-sdk'; import {
AuditOperationSubTypes,
AuditOperationTypes,
AuditRowUpdateReqType,
} from 'nocodb-sdk';
import Model from '../models/Model'; import Model from '../models/Model';
import { PagedResponseImpl } from '../meta/helpers/PagedResponse'; import { PagedResponseImpl } from '../meta/helpers/PagedResponse';
@ -12,7 +12,7 @@ import DOMPurify from 'isomorphic-dompurify';
export async function commentRow(param: { export async function commentRow(param: {
rowId: string; rowId: string;
body: CommentRowPayloadType; body: AuditRowUpdateReqType;
user: any; user: any;
}) { }) {
await validatePayload( await validatePayload(
@ -29,7 +29,7 @@ export async function commentRow(param: {
export async function auditRowUpdate(param: { export async function auditRowUpdate(param: {
rowId: string; rowId: string;
body: AuditRowUpdatePayloadType; body: AuditRowUpdateReqType;
}) { }) {
await validatePayload( await validatePayload(
'swagger.json#/components/schemas/AuditRowUpdateReq', 'swagger.json#/components/schemas/AuditRowUpdateReq',

6
packages/nocodb/src/lib/services/dataService/export.ts

@ -1,10 +1,6 @@
import { import { getViewAndModelByAliasOrId, PathParams } from './helpers';
getViewAndModelByAliasOrId,
PathParams,
} from './helpers';
import { View } from '../../models'; import { View } from '../../models';
// Todo: bring logic from controller // Todo: bring logic from controller
export async function excelDataExport( export async function excelDataExport(
param: PathParams & { param: PathParams & {

5
packages/nocodb/src/lib/services/projectUserService.ts

@ -292,9 +292,8 @@ export async function sendInviteEmail(
req: any req: any
): Promise<any> { ): Promise<any> {
try { try {
const template = ( const template = (await import('./userService/ui/emailTemplates/invite'))
await import('./userService/ui/emailTemplates/invite') .default;
).default;
const emailAdapter = await NcPluginMgrv2.emailAdapter(); const emailAdapter = await NcPluginMgrv2.emailAdapter();

6
packages/nocodb/src/lib/services/syncService/helpers/job.ts

@ -679,8 +679,6 @@ export default async (
); );
} }
// debug
// console.log(JSON.stringify(tables, null, 2));
return tables; return tables;
} }
@ -1413,7 +1411,7 @@ export default async (
case UITypes.DateTime: case UITypes.DateTime:
case UITypes.CreateTime: case UITypes.CreateTime:
case UITypes.LastModifiedTime: case UITypes.LastModifiedTime:
rec[key] = dayjs(value).utc().format('YYYY-MM-DD HH:mm'); rec[key] = dayjs(value).format('YYYY-MM-DD HH:mm');
break; break;
case UITypes.Date: case UITypes.Date:
@ -1422,7 +1420,7 @@ export default async (
rec[key] = null; rec[key] = null;
logBasic(`:: Invalid date ${value}`); logBasic(`:: Invalid date ${value}`);
} else { } else {
rec[key] = dayjs(value).utc().format('YYYY-MM-DD'); rec[key] = dayjs(value).format('YYYY-MM-DD');
} }
break; break;

3
packages/nocodb/src/lib/services/tableService.ts

@ -51,7 +51,7 @@ export async function tableUpdate(param: {
if ('meta' in param.table) { if ('meta' in param.table) {
await Model.updateMeta(param.tableId, param.table.meta); await Model.updateMeta(param.tableId, param.table.meta);
return { msg: 'success' } return true;
} }
if (!param.table.table_name) { if (!param.table.table_name) {
@ -201,7 +201,6 @@ export async function tableDelete(param: {
return table.delete(); return table.delete();
} }
export async function getTableWithAccessibleViews(param: { export async function getTableWithAccessibleViews(param: {
tableId: string; tableId: string;
user: User; user: User;

Loading…
Cancel
Save