From 0177f775fc97525f99fe689abef1e49d78ea4b0b Mon Sep 17 00:00:00 2001 From: chenos Date: Tue, 3 Jan 2023 15:17:20 +0800 Subject: [PATCH] fix: code format --- packages/samples/hello/src/server/index.ts | 1 - .../samples/shop-actions/src/server/index.ts | 33 +++++++++---------- .../samples/shop-events/src/server/index.ts | 33 ++++++++++--------- .../samples/shop-i18n/src/server/index.ts | 9 +++-- .../samples/shop-modeling/src/server/index.ts | 3 +- 5 files changed, 39 insertions(+), 40 deletions(-) diff --git a/packages/samples/hello/src/server/index.ts b/packages/samples/hello/src/server/index.ts index fb8ba9199e..8eae593ecc 100644 --- a/packages/samples/hello/src/server/index.ts +++ b/packages/samples/hello/src/server/index.ts @@ -1,7 +1,6 @@ import { InstallOptions, Plugin } from '@nocobase/server'; export class HelloPlugin extends Plugin { - beforeLoad() { // TODO } diff --git a/packages/samples/shop-actions/src/server/index.ts b/packages/samples/shop-actions/src/server/index.ts index 9cce263247..99d0121929 100644 --- a/packages/samples/shop-actions/src/server/index.ts +++ b/packages/samples/shop-actions/src/server/index.ts @@ -3,7 +3,6 @@ import path from 'path'; import { InstallOptions, Plugin } from '@nocobase/server'; export class ShopPlugin extends Plugin { - beforeLoad() { // TODO } @@ -19,7 +18,7 @@ export class ShopPlugin extends Plugin { create: { blacklist: ['id', 'totalPrice', 'status', 'createdAt', 'updatedAt'], values: { - status: 0 + status: 0, }, middlewares: [ async (ctx, next) => { @@ -30,9 +29,9 @@ export class ShopPlugin extends Plugin { filter: { enabled: true, inventory: { - $gt: 0 - } - } + $gt: 0, + }, + }, }); if (!product) { @@ -42,7 +41,7 @@ export class ShopPlugin extends Plugin { ctx.state.product = product; await next(); - } + }, ], async handler(ctx, next) { const { product } = ctx.state; @@ -51,22 +50,22 @@ export class ShopPlugin extends Plugin { ...ctx.action.params.values, productId: product.id, quantity: 1, - totalPrice: product.price - } + totalPrice: product.price, + }, }); ctx.body = order; - } + }, }, list: { filter: { // 由 users 插件扩展的过滤器运算符 $isCurrentUser: true, status: { - $ne: -1 - } + $ne: -1, + }, }, - fields: ['id', 'status', 'createdAt', 'updatedAt'] + fields: ['id', 'status', 'createdAt', 'updatedAt'], }, async deliver(ctx, next) { const { filterByTk } = ctx.action.params; @@ -78,17 +77,17 @@ export class ShopPlugin extends Plugin { status: 2, delivery: { ...ctx.action.params.values, - status: 0 - } - } + status: 0, + }, + }, }); order.delivery = await order.getDelivery(); ctx.body = order; next(); - } - } + }, + }, }); this.app.acl.allow('products', '*'); diff --git a/packages/samples/shop-events/src/server/index.ts b/packages/samples/shop-events/src/server/index.ts index c1b54f10f9..eeb12bcfed 100644 --- a/packages/samples/shop-events/src/server/index.ts +++ b/packages/samples/shop-events/src/server/index.ts @@ -14,27 +14,27 @@ export class ShopPlugin extends Plugin { filter: { status: 0, createdAt: { - $lt: expiredDate - } - } + $lt: expiredDate, + }, + }, }); await deliveryRepo.update({ filter: { - id: expiredDeliveries.map(item => item.get('id')), + id: expiredDeliveries.map((item) => item.get('id')), }, values: { - status: 1 - } + status: 1, + }, }); const orderRepo = this.db.getRepository('orders'); const [updated] = await orderRepo.update({ filter: { status: 2, - id: expiredDeliveries.map(item => item.get('orderId')) + id: expiredDeliveries.map((item) => item.get('orderId')), }, values: { - status: 3 - } + status: 3, + }, }); console.log('%d orders expired', updated); @@ -51,14 +51,17 @@ export class ShopPlugin extends Plugin { this.db.on('orders.afterCreate', async (order, options) => { const product = await order.getProduct({ - transaction: options.transaction + transaction: options.transaction, }); - await product.update({ - inventory: product.inventory - order.quantity - }, { - transaction: options.transaction - }); + await product.update( + { + inventory: product.inventory - order.quantity, + }, + { + transaction: options.transaction, + }, + ); }); this.app.on('beforeStart', () => { diff --git a/packages/samples/shop-i18n/src/server/index.ts b/packages/samples/shop-i18n/src/server/index.ts index 9951916f97..84a6885397 100644 --- a/packages/samples/shop-i18n/src/server/index.ts +++ b/packages/samples/shop-i18n/src/server/index.ts @@ -7,7 +7,6 @@ import zhCN from './locales/zh-CN'; const ns = '@nocobase/plugin-sample-shop-i18n'; export class ShopPlugin extends Plugin { - beforeLoad() { // TODO } @@ -44,13 +43,13 @@ export class ShopPlugin extends Plugin { productId: product.id, quantity: 1, totalPrice: product.price, - userId: ctx.state.currentUser.id - } + userId: ctx.state.currentUser.id, + }, }); next(); - } - } + }, + }, }); this.app.acl.allow('products', '*'); diff --git a/packages/samples/shop-modeling/src/server/index.ts b/packages/samples/shop-modeling/src/server/index.ts index 4a1275277a..5fcfa57c37 100644 --- a/packages/samples/shop-modeling/src/server/index.ts +++ b/packages/samples/shop-modeling/src/server/index.ts @@ -5,10 +5,9 @@ import { InstallOptions, Plugin } from '@nocobase/server'; import SnowflakeField from './fields/SnowflakeField'; export class ShopPlugin extends Plugin { - afterAdd() { this.db.registerFieldTypes({ - snowflake: SnowflakeField + snowflake: SnowflakeField, }); }