fix: code format

This commit is contained in:
chenos 2023-01-03 15:17:20 +08:00
parent 9d618315ae
commit 0177f775fc
5 changed files with 39 additions and 40 deletions

View File

@ -1,7 +1,6 @@
import { InstallOptions, Plugin } from '@nocobase/server';
export class HelloPlugin extends Plugin {
beforeLoad() {
// TODO
}

View File

@ -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', '*');

View File

@ -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', () => {

View File

@ -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', '*');

View File

@ -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,
});
}