Browse Source

chore: lint

pull/5444/head
Wing-Kam Wong 1 year ago
parent
commit
dd08439e0c
  1. 15
      packages/nocodb-nest/src/db/formulav2/formulaQueryBuilderv2.ts
  2. 14
      packages/nocodb-nest/src/db/functionMappings/pg.ts
  3. 44
      packages/nocodb-nest/src/helpers/convertDateFormat.ts
  4. 12
      packages/nocodb-nest/src/helpers/formulaFnHelper.ts
  5. 9
      packages/nocodb-nest/src/modules/project-users/project-users.service.ts
  6. 1
      packages/nocodb-nest/src/modules/tables/tables.service.ts
  7. 7
      packages/nocodb-nest/src/modules/users/users.service.ts
  8. 2
      packages/nocodb-nest/src/plugins/vultr/index.ts

15
packages/nocodb-nest/src/db/formulav2/formulaQueryBuilderv2.ts

@ -3,7 +3,10 @@ import { jsepCurlyHook, UITypes } from 'nocodb-sdk';
import mapFunctionName from '../mapFunctionName'; import mapFunctionName from '../mapFunctionName';
import genRollupSelectv2 from '../genRollupSelectv2'; import genRollupSelectv2 from '../genRollupSelectv2';
import FormulaColumn from '../../models/FormulaColumn'; import FormulaColumn from '../../models/FormulaColumn';
import { convertDateFormatForConcat, validateDateWithUnknownFormat } from '../../helpers/formulaFnHelper'; import {
convertDateFormatForConcat,
validateDateWithUnknownFormat,
} from '../../helpers/formulaFnHelper';
import { CacheGetType, CacheScope } from '../../utils/globals'; import { CacheGetType, CacheScope } from '../../utils/globals';
import NocoCache from '../../cache/NocoCache'; import NocoCache from '../../cache/NocoCache';
import type { XKnex } from '../CustomKnex'; import type { XKnex } from '../CustomKnex';
@ -640,7 +643,7 @@ async function _formulaQueryBuilder(
arg, arg,
columnIdToUidt, columnIdToUidt,
query, query,
knex.clientType() knex.clientType(),
); );
} else { } else {
// sqlite3: special handling - See BinaryExpression // sqlite3: special handling - See BinaryExpression
@ -657,9 +660,9 @@ async function _formulaQueryBuilder(
} }
} }
return query; return query;
}) }),
) )
).join()})${colAlias}`.replace(/\?/g, '\\?') ).join()})${colAlias}`.replace(/\?/g, '\\?'),
), ),
}; };
} else if (pt.type === 'Literal') { } else if (pt.type === 'Literal') {
@ -741,13 +744,13 @@ async function _formulaQueryBuilder(
pt.left?.arguments?.[0], pt.left?.arguments?.[0],
columnIdToUidt, columnIdToUidt,
left, left,
knex.clientType() knex.clientType(),
); );
right = await convertDateFormatForConcat( right = await convertDateFormatForConcat(
pt.right?.arguments?.[0], pt.right?.arguments?.[0],
columnIdToUidt, columnIdToUidt,
right, right,
knex.clientType() knex.clientType(),
); );
// handle NULL values when calling CONCAT for sqlite3 // handle NULL values when calling CONCAT for sqlite3

14
packages/nocodb-nest/src/db/functionMappings/pg.ts

@ -16,10 +16,10 @@ const pg = {
return { return {
builder: args.knex.raw( builder: args.knex.raw(
`POSITION(${args.knex.raw( `POSITION(${args.knex.raw(
(await args.fn(args.pt.arguments[1])).builder.toQuery() (await args.fn(args.pt.arguments[1])).builder.toQuery(),
)} in ${args.knex.raw( )} in ${args.knex.raw(
(await args.fn(args.pt.arguments[0])).builder.toQuery() (await args.fn(args.pt.arguments[0])).builder.toQuery(),
)})${args.colAlias}` )})${args.colAlias}`,
), ),
}; };
}, },
@ -160,13 +160,13 @@ const pg = {
`${( `${(
await Promise.all( await Promise.all(
args.pt.arguments.map(async (ar) => args.pt.arguments.map(async (ar) =>
(await args.fn(ar, '', 'OR')).builder.toQuery() (await args.fn(ar, '', 'OR')).builder.toQuery(),
) ),
) )
).join(' OR ')}` ).join(' OR ')}`,
) )
.wrap('(', ')') .wrap('(', ')')
.toQuery()} THEN TRUE ELSE FALSE END ${args.colAlias}` .toQuery()} THEN TRUE ELSE FALSE END ${args.colAlias}`,
), ),
}; };
}, },

44
packages/nocodb-nest/src/helpers/convertDateFormat.ts

@ -1,23 +1,23 @@
export function convertDateFormat(date_format: string, type: string) { export function convertDateFormat(date_format: string, type: string) {
if (date_format === 'YYYY-MM-DD') { if (date_format === 'YYYY-MM-DD') {
if (type === 'mysql2' || type === 'sqlite3') return '%Y-%m-%d'; if (type === 'mysql2' || type === 'sqlite3') return '%Y-%m-%d';
} else if (date_format === 'YYYY/MM/DD') { } else if (date_format === 'YYYY/MM/DD') {
if (type === 'mysql2' || type === 'sqlite3') return '%Y/%m/%d'; if (type === 'mysql2' || type === 'sqlite3') return '%Y/%m/%d';
} else if (date_format === 'DD-MM-YYYY') { } else if (date_format === 'DD-MM-YYYY') {
if (type === 'mysql2' || type === 'sqlite3') return '%d/%m/%Y'; if (type === 'mysql2' || type === 'sqlite3') return '%d/%m/%Y';
} else if (date_format === 'MM-DD-YYYY') { } else if (date_format === 'MM-DD-YYYY') {
if (type === 'mysql2' || type === 'sqlite3') return '%d-%m-%Y'; if (type === 'mysql2' || type === 'sqlite3') return '%d-%m-%Y';
} else if (date_format === 'DD/MM/YYYY') { } else if (date_format === 'DD/MM/YYYY') {
if (type === 'mysql2' || type === 'sqlite3') return '%d/%m/%Y'; if (type === 'mysql2' || type === 'sqlite3') return '%d/%m/%Y';
} else if (date_format === 'MM/DD/YYYY') { } else if (date_format === 'MM/DD/YYYY') {
if (type === 'mysql2' || type === 'sqlite3') return '%m-%d-%Y'; if (type === 'mysql2' || type === 'sqlite3') return '%m-%d-%Y';
} else if (date_format === 'DD MM YYYY') { } else if (date_format === 'DD MM YYYY') {
if (type === 'mysql2' || type === 'sqlite3') return '%d %m %Y'; if (type === 'mysql2' || type === 'sqlite3') return '%d %m %Y';
} else if (date_format === 'MM DD YYYY') { } else if (date_format === 'MM DD YYYY') {
if (type === 'mysql2' || type === 'sqlite3') return '%m %d %Y'; if (type === 'mysql2' || type === 'sqlite3') return '%m %d %Y';
} else if (date_format === 'YYYY MM DD') { } else if (date_format === 'YYYY MM DD') {
if (type === 'mysql2' || type === 'sqlite3') return '%Y %m %d'; if (type === 'mysql2' || type === 'sqlite3') return '%Y %m %d';
} }
// pg / mssql // pg / mssql
return date_format; return date_format;
} }

12
packages/nocodb-nest/src/helpers/formulaFnHelper.ts

@ -60,7 +60,7 @@ export async function convertDateFormatForConcat(
o, o,
columnIdToUidt, columnIdToUidt,
query, query,
clientType clientType,
) { ) {
if ( if (
o?.type === 'Identifier' && o?.type === 'Identifier' &&
@ -76,24 +76,24 @@ export async function convertDateFormatForConcat(
if (clientType === 'mysql2') { if (clientType === 'mysql2') {
query = `DATE_FORMAT(${query}, '${convertDateFormat( query = `DATE_FORMAT(${query}, '${convertDateFormat(
meta.date_format, meta.date_format,
clientType clientType,
)}')`; )}')`;
} else if (clientType === 'pg') { } else if (clientType === 'pg') {
query = `TO_CHAR(${query}, '${convertDateFormat( query = `TO_CHAR(${query}, '${convertDateFormat(
meta.date_format, meta.date_format,
clientType clientType,
)}')`; )}')`;
} else if (clientType === 'sqlite3') { } else if (clientType === 'sqlite3') {
query = `strftime('${convertDateFormat( query = `strftime('${convertDateFormat(
meta.date_format, meta.date_format,
clientType clientType,
)}', ${query})`; )}', ${query})`;
} else if (clientType === 'mssql') { } else if (clientType === 'mssql') {
query = `FORMAT(${query}, '${convertDateFormat( query = `FORMAT(${query}, '${convertDateFormat(
meta.date_format, meta.date_format,
clientType clientType,
)}')`; )}')`;
} }
} }
return query; return query;
} }

9
packages/nocodb-nest/src/modules/project-users/project-users.service.ts

@ -1,5 +1,10 @@
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { AuditOperationSubTypes, AuditOperationTypes, OrgUserRoles, PluginCategory } from 'nocodb-sdk' import {
AuditOperationSubTypes,
AuditOperationTypes,
OrgUserRoles,
PluginCategory,
} from 'nocodb-sdk';
import { T } from 'nc-help'; import { T } from 'nc-help';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import * as ejs from 'ejs'; import * as ejs from 'ejs';
@ -283,7 +288,7 @@ export class ProjectUsersService {
await Audit.insert({ await Audit.insert({
op_type: AuditOperationTypes.AUTHENTICATION, op_type: AuditOperationTypes.AUTHENTICATION,
op_sub_type: AuditOperationSubTypes.RESEND_INVITE , op_sub_type: AuditOperationSubTypes.RESEND_INVITE,
user: user.email, user: user.email,
description: `resent a invite to ${user.email} `, description: `resent a invite to ${user.email} `,
ip: param.req.clientIp, ip: param.req.clientIp,

1
packages/nocodb-nest/src/modules/tables/tables.service.ts

@ -1,4 +1,3 @@
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import DOMPurify from 'isomorphic-dompurify'; import DOMPurify from 'isomorphic-dompurify';
import { import {

7
packages/nocodb-nest/src/modules/users/users.service.ts

@ -1,6 +1,11 @@
import { promisify } from 'util'; import { promisify } from 'util';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { AuditOperationSubTypes, AuditOperationTypes, OrgUserRoles, validatePassword } from 'nocodb-sdk' import {
AuditOperationSubTypes,
AuditOperationTypes,
OrgUserRoles,
validatePassword,
} from 'nocodb-sdk';
import { v4 as uuidv4 } from 'uuid'; import { v4 as uuidv4 } from 'uuid';
import { isEmail } from 'validator'; import { isEmail } from 'validator';
import { T } from 'nc-help'; import { T } from 'nc-help';

2
packages/nocodb-nest/src/plugins/vultr/index.ts

@ -25,7 +25,7 @@ const config: XcPluginConfig = {
label: 'Host Name', label: 'Host Name',
placeholder: 'e.g.: ewr1.vultrobjects.com', placeholder: 'e.g.: ewr1.vultrobjects.com',
type: XcType.SingleLineText, type: XcType.SingleLineText,
required: true required: true,
}, },
{ {
key: 'access_key', key: 'access_key',

Loading…
Cancel
Save