Browse Source

barcode: fix linter issues

pull/4641/head
flisowna 2 years ago
parent
commit
e90e978bd5
  1. 1
      packages/nc-gui/components/smartsheet/Gallery.vue
  2. 81
      packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts
  3. 2
      packages/nocodb/src/lib/migrations/v2/nc_024_barcode_column_type.ts
  4. 11
      packages/nocodb/src/lib/models/Base.ts
  5. 2
      packages/nocodb/src/lib/models/Column.ts

1
packages/nc-gui/components/smartsheet/Gallery.vue

@ -1,6 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import { ViewTypes, isVirtualCol } from 'nocodb-sdk' import { ViewTypes, isVirtualCol } from 'nocodb-sdk'
import VueBarcode from '@chenfengyuan/vue-barcode'
import { import {
ActiveViewInj, ActiveViewInj,
ChangePageInj, ChangePageInj,

81
packages/nocodb/src/lib/db/sql-data-mapper/lib/sql/BaseModelSqlv2.ts

@ -101,7 +101,7 @@ class BaseModelSqlv2 {
qb.where(_wherePk(this.model.primaryKeys, id)); qb.where(_wherePk(this.model.primaryKeys, id));
let data = (await this.execAndParse(qb))?.[0]; const data = (await this.execAndParse(qb))?.[0];
if (data) { if (data) {
const proto = await this.getProto(); const proto = await this.getProto();
@ -159,7 +159,7 @@ class BaseModelSqlv2 {
qb.orderBy(this.model.primaryKey.column_name); qb.orderBy(this.model.primaryKey.column_name);
} }
let data = await qb.first(); const data = await qb.first();
if (data) { if (data) {
const proto = await this.getProto(); const proto = await this.getProto();
@ -253,7 +253,7 @@ class BaseModelSqlv2 {
if (!ignoreViewFilterAndSort) applyPaginate(qb, rest); if (!ignoreViewFilterAndSort) applyPaginate(qb, rest);
const proto = await this.getProto(); const proto = await this.getProto();
let data = await this.execAndParse(qb); const data = await this.execAndParse(qb);
return data?.map((d) => { return data?.map((d) => {
d.__proto__ = proto; d.__proto__ = proto;
@ -321,7 +321,8 @@ class BaseModelSqlv2 {
as: 'count', as: 'count',
}).first(); }).first();
const res = (await this.dbDriver.raw(unsanitize(qb.toQuery()))) as any; const res = (await this.dbDriver.raw(unsanitize(qb.toQuery()))) as any;
return ((this.isPg || this.isSnowflake) ? res.rows[0] : res[0][0] ?? res[0]).count; return (this.isPg || this.isSnowflake ? res.rows[0] : res[0][0] ?? res[0])
.count;
} }
// todo: add support for sortArrJson and filterArrJson // todo: add support for sortArrJson and filterArrJson
@ -424,7 +425,7 @@ class BaseModelSqlv2 {
.as('list') .as('list')
); );
let children = await this.execAndParse(childQb, childTable); const children = await this.execAndParse(childQb, childTable);
const proto = await ( const proto = await (
await Model.getBaseModelSQL({ await Model.getBaseModelSQL({
id: childTable.id, id: childTable.id,
@ -551,7 +552,7 @@ class BaseModelSqlv2 {
await childModel.selectObject({ qb }); await childModel.selectObject({ qb });
let children = await this.execAndParse(qb, childTable); const children = await this.execAndParse(qb, childTable);
const proto = await ( const proto = await (
await Model.getBaseModelSQL({ await Model.getBaseModelSQL({
@ -736,7 +737,7 @@ class BaseModelSqlv2 {
qb.limit(+rest?.limit || 25); qb.limit(+rest?.limit || 25);
qb.offset(+rest?.offset || 0); qb.offset(+rest?.offset || 0);
let children = await this.execAndParse(qb, childTable); const children = await this.execAndParse(qb, childTable);
const proto = await ( const proto = await (
await Model.getBaseModelSQL({ id: rtnId, dbDriver: this.dbDriver }) await Model.getBaseModelSQL({ id: rtnId, dbDriver: this.dbDriver })
).getProto(); ).getProto();
@ -962,7 +963,7 @@ class BaseModelSqlv2 {
applyPaginate(qb, rest); applyPaginate(qb, rest);
const proto = await childModel.getProto(); const proto = await childModel.getProto();
let data = await qb; const data = await qb;
return data.map((c) => { return data.map((c) => {
c.__proto__ = proto; c.__proto__ = proto;
return c; return c;
@ -1076,7 +1077,7 @@ class BaseModelSqlv2 {
applyPaginate(qb, rest); applyPaginate(qb, rest);
const proto = await childModel.getProto(); const proto = await childModel.getProto();
let data = await this.execAndParse(qb, childTable); const data = await this.execAndParse(qb, childTable);
return data.map((c) => { return data.map((c) => {
c.__proto__ = proto; c.__proto__ = proto;
@ -1194,7 +1195,7 @@ class BaseModelSqlv2 {
applyPaginate(qb, rest); applyPaginate(qb, rest);
const proto = await parentModel.getProto(); const proto = await parentModel.getProto();
let data = await this.execAndParse(qb, childTable); const data = await this.execAndParse(qb, childTable);
return data.map((c) => { return data.map((c) => {
c.__proto__ = proto; c.__proto__ = proto;
@ -1486,7 +1487,9 @@ class BaseModelSqlv2 {
} }
break; break;
default: { default: {
qb.select({ [column.column_name]: barcodeValueColumn.column_name }); qb.select({
[column.column_name]: barcodeValueColumn.column_name,
});
break; break;
} }
} }
@ -1591,10 +1594,11 @@ class BaseModelSqlv2 {
.max(ai.column_name, { as: 'id' }) .max(ai.column_name, { as: 'id' })
)[0].id; )[0].id;
} else if (this.isSnowflake) { } else if (this.isSnowflake) {
id = (( id = (
await this.dbDriver(this.tnPath) (await this.dbDriver(this.tnPath).max(ai.column_name, {
.max(ai.column_name, { as: 'id' }) as: 'id',
) as any)[0].id; })) as any
)[0].id;
} }
response = await this.readByPk(id); response = await this.readByPk(id);
} else { } else {
@ -1710,7 +1714,11 @@ class BaseModelSqlv2 {
if (this.isMssql && schema) { if (this.isMssql && schema) {
return this.dbDriver.raw('??.??', [schema, tb.table_name]); return this.dbDriver.raw('??.??', [schema, tb.table_name]);
} else if (this.isSnowflake) { } else if (this.isSnowflake) {
return [this.dbDriver.client.config.connection.database, this.dbDriver.client.config.connection.schema, tb.table_name].join('.'); return [
this.dbDriver.client.config.connection.database,
this.dbDriver.client.config.connection.schema,
tb.table_name,
].join('.');
} else { } else {
return tb.table_name; return tb.table_name;
} }
@ -1850,10 +1858,11 @@ class BaseModelSqlv2 {
.max(ai.column_name, { as: 'id' }) .max(ai.column_name, { as: 'id' })
)[0].id; )[0].id;
} else if (this.isSnowflake) { } else if (this.isSnowflake) {
id = (( id = (
await this.dbDriver(this.tnPath) (await this.dbDriver(this.tnPath).max(ai.column_name, {
.max(ai.column_name, { as: 'id' }) as: 'id',
) as any).rows[0].id; })) as any
).rows[0].id;
} }
response = await this.readByPk(id); response = await this.readByPk(id);
} else { } else {
@ -2043,9 +2052,7 @@ class BaseModelSqlv2 {
const res = []; const res = [];
for (const d of deleteIds) { for (const d of deleteIds) {
if (Object.keys(d).length) { if (Object.keys(d).length) {
const response = await transaction(this.tnPath) const response = await transaction(this.tnPath).del().where(d);
.del()
.where(d);
res.push(response); res.push(response);
} }
} }
@ -2417,20 +2424,19 @@ class BaseModelSqlv2 {
if (this.isSnowflake) { if (this.isSnowflake) {
const parentPK = this.dbDriver(parentTn) const parentPK = this.dbDriver(parentTn)
.select(parentColumn.column_name) .select(parentColumn.column_name)
.where(_wherePk(parentTable.primaryKeys, childId)) .where(_wherePk(parentTable.primaryKeys, childId))
.first(); .first();
const childPK = this.dbDriver(childTn) const childPK = this.dbDriver(childTn)
.select(childColumn.column_name) .select(childColumn.column_name)
.where(_wherePk(childTable.primaryKeys, rowId)) .where(_wherePk(childTable.primaryKeys, rowId))
.first(); .first();
await this.dbDriver.raw(`INSERT INTO ?? (??, ??) SELECT (${parentPK.toQuery()}), (${childPK.toQuery()})`, [ await this.dbDriver.raw(
vTn, `INSERT INTO ?? (??, ??) SELECT (${parentPK.toQuery()}), (${childPK.toQuery()})`,
vParentCol.column_name, [vTn, vParentCol.column_name, vChildCol.column_name]
vChildCol.column_name, );
])
} else { } else {
await this.dbDriver(vTn).insert({ await this.dbDriver(vTn).insert({
[vParentCol.column_name]: this.dbDriver(parentTn) [vParentCol.column_name]: this.dbDriver(parentTn)
@ -2731,7 +2737,7 @@ class BaseModelSqlv2 {
const proto = await this.getProto(); const proto = await this.getProto();
let data = await groupedQb; const data = await groupedQb;
const result = data?.map((d) => { const result = data?.map((d) => {
d.__proto__ = proto; d.__proto__ = proto;
return d; return d;
@ -2834,10 +2840,7 @@ class BaseModelSqlv2 {
return await qb; return await qb;
} }
private async execAndParse( private async execAndParse(qb: Knex.QueryBuilder, childTable?: Model) {
qb: Knex.QueryBuilder,
childTable?: Model
) {
let query = qb.toQuery(); let query = qb.toQuery();
if (!this.isPg && !this.isMssql && !this.isSnowflake) { if (!this.isPg && !this.isMssql && !this.isSnowflake) {
query = unsanitize(qb.toQuery()); query = unsanitize(qb.toQuery());

2
packages/nocodb/src/lib/migrations/v2/nc_024_barcode_column_type.ts

@ -23,4 +23,4 @@ const down = async (knex: Knex) => {
await knex.schema.dropTable(MetaTable.COL_BARCODE); await knex.schema.dropTable(MetaTable.COL_BARCODE);
}; };
export { up, down }; export { up, down };

11
packages/nocodb/src/lib/models/Base.ts

@ -108,7 +108,7 @@ export default class Base implements BaseType {
'order', 'order',
'enabled', 'enabled',
]); ]);
if (updateObj.config) { if (updateObj.config) {
updateObj.config = CryptoJS.AES.encrypt( updateObj.config = CryptoJS.AES.encrypt(
JSON.stringify(base.config), JSON.stringify(base.config),
@ -164,9 +164,7 @@ export default class Base implements BaseType {
await NocoCache.setList(CacheScope.BASE, [args.projectId], baseDataList); await NocoCache.setList(CacheScope.BASE, [args.projectId], baseDataList);
} }
baseDataList.sort( baseDataList.sort((a, b) => (a.order ?? Infinity) - (b.order ?? Infinity));
(a, b) => (a.order ?? Infinity) - (b.order ?? Infinity)
);
return baseDataList?.map((baseData) => { return baseDataList?.map((baseData) => {
return new Base(baseData); return new Base(baseData);
@ -206,7 +204,6 @@ export default class Base implements BaseType {
// update order for bases // update order for bases
for (const [i, b] of Object.entries(bases)) { for (const [i, b] of Object.entries(bases)) {
await NocoCache.deepDel( await NocoCache.deepDel(
CacheScope.BASE, CacheScope.BASE,
`${CacheScope.BASE}:${b.id}`, `${CacheScope.BASE}:${b.id}`,
@ -220,11 +217,11 @@ export default class Base implements BaseType {
null, null,
MetaTable.BASES, MetaTable.BASES,
{ {
order: b.order order: b.order,
}, },
b.id b.id
); );
await NocoCache.appendToList( await NocoCache.appendToList(
CacheScope.BASE, CacheScope.BASE,
[b.project_id], [b.project_id],

2
packages/nocodb/src/lib/models/Column.ts

@ -6,8 +6,8 @@ import SelectOption from './SelectOption';
import Model from './Model'; import Model from './Model';
import NocoCache from '../cache/NocoCache'; import NocoCache from '../cache/NocoCache';
import { import {
ColumnReqType,
AllowedColumnTypesForQrAndBarcodes, AllowedColumnTypesForQrAndBarcodes,
ColumnReqType,
ColumnType, ColumnType,
UITypes, UITypes,
} from 'nocodb-sdk'; } from 'nocodb-sdk';

Loading…
Cancel
Save