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

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

@ -16,10 +16,10 @@ const pg = {
return {
builder: 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(
(await args.fn(args.pt.arguments[0])).builder.toQuery()
)})${args.colAlias}`
(await args.fn(args.pt.arguments[0])).builder.toQuery(),
)})${args.colAlias}`,
),
};
},
@ -160,13 +160,13 @@ const pg = {
`${(
await Promise.all(
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('(', ')')
.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) {
if (date_format === 'YYYY-MM-DD') {
if (type === 'mysql2' || type === 'sqlite3') return '%Y-%m-%d';
} else if (date_format === 'YYYY/MM/DD') {
if (type === 'mysql2' || type === 'sqlite3') return '%Y/%m/%d';
} else if (date_format === 'DD-MM-YYYY') {
if (type === 'mysql2' || type === 'sqlite3') return '%d/%m/%Y';
} else if (date_format === 'MM-DD-YYYY') {
if (type === 'mysql2' || type === 'sqlite3') return '%d-%m-%Y';
} else if (date_format === 'DD/MM/YYYY') {
if (type === 'mysql2' || type === 'sqlite3') return '%d/%m/%Y';
} else if (date_format === 'MM/DD/YYYY') {
if (type === 'mysql2' || type === 'sqlite3') return '%m-%d-%Y';
} else if (date_format === 'DD MM YYYY') {
if (type === 'mysql2' || type === 'sqlite3') return '%d %m %Y';
} else if (date_format === 'MM DD YYYY') {
if (type === 'mysql2' || type === 'sqlite3') return '%m %d %Y';
} else if (date_format === 'YYYY MM DD') {
if (type === 'mysql2' || type === 'sqlite3') return '%Y %m %d';
}
// pg / mssql
return date_format;
}
if (date_format === 'YYYY-MM-DD') {
if (type === 'mysql2' || type === 'sqlite3') return '%Y-%m-%d';
} else if (date_format === 'YYYY/MM/DD') {
if (type === 'mysql2' || type === 'sqlite3') return '%Y/%m/%d';
} else if (date_format === 'DD-MM-YYYY') {
if (type === 'mysql2' || type === 'sqlite3') return '%d/%m/%Y';
} else if (date_format === 'MM-DD-YYYY') {
if (type === 'mysql2' || type === 'sqlite3') return '%d-%m-%Y';
} else if (date_format === 'DD/MM/YYYY') {
if (type === 'mysql2' || type === 'sqlite3') return '%d/%m/%Y';
} else if (date_format === 'MM/DD/YYYY') {
if (type === 'mysql2' || type === 'sqlite3') return '%m-%d-%Y';
} else if (date_format === 'DD MM YYYY') {
if (type === 'mysql2' || type === 'sqlite3') return '%d %m %Y';
} else if (date_format === 'MM DD YYYY') {
if (type === 'mysql2' || type === 'sqlite3') return '%m %d %Y';
} else if (date_format === 'YYYY MM DD') {
if (type === 'mysql2' || type === 'sqlite3') return '%Y %m %d';
}
// pg / mssql
return date_format;
}

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

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

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

@ -1,5 +1,10 @@
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 { v4 as uuidv4 } from 'uuid';
import * as ejs from 'ejs';
@ -283,7 +288,7 @@ export class ProjectUsersService {
await Audit.insert({
op_type: AuditOperationTypes.AUTHENTICATION,
op_sub_type: AuditOperationSubTypes.RESEND_INVITE ,
op_sub_type: AuditOperationSubTypes.RESEND_INVITE,
user: user.email,
description: `resent a invite to ${user.email} `,
ip: param.req.clientIp,

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

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

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

@ -1,6 +1,11 @@
import { promisify } from 'util';
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 { isEmail } from 'validator';
import { T } from 'nc-help';

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

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

Loading…
Cancel
Save