* fix: add field linkage on setting default datetime * fix: fix dateonly timezone problem * fix: improve test * docs(DatePicker): add demos * fix(DatePicker): should return the beginning of a second * feat(DatePicker): support non-UTC * refactor: rename * fix(RangePicker): get correct end date * test(mapDatePicker): add test * test(mapRangePicker): add test * feat(Filter): use non-UTC to filter * feat(FilterBlock): use non-UTC to filter * feat: add '$dateBetween' operator in datetime * feat: use RangePicker on toggled to 'dateBetween' operator * feat: set ranges for RangePicker * feat: backend support to parse 'dateBetween' operator * fix: fix build error * fix: adaptive content width * feat: support to use var on data scope * feat: add parse-variables plugin * feat: support to parse variables * feat: support only to set system variables * test: rename * feat: cover all * fix: fix build error * feat(RangePicker): extend more shortcut keys * feat(parse-variables): support more date var * feat: support user variables * feat: disable unmatched options * fix: use component name to filter option * fix: fix build error * feat: remove some operator of id * chore: remove useless operators * fix: built in plugin * refactor: move to core from plugin * refactor: remove code of plugin * refactor: remove useless code * fix: should after acl * Update server.ts * fix: compatible with old version * feat: test cases * refactor: rename to 'is between' * refactor: parse filter * fix: improve code * feat: test cases * fix: fix error * fix: improve parse date * fix: date variables * fix: day range * fix: test error * fix: typo * fix: test error * feat: $user variable * fix: toDate * fix: fix the value range of shortcuts * feat: add quarter and test * feat: support to use user's association fields to filter * refactor: use maxDepth * refactor: remove useless code * fix: make AssociationSelect.Designer to support variables * fix: getField * fix: parse utc * fix: remove only * fix: filter by ctx.db.getFieldByPath * fix: avoid error * fix: add translation * fix(RangePicker): can be set to empty * feat(utils): add hasEmptyValue * fix: should not save empty * fix: last few days should include today * fix: limit user variable type to display * fix: parse filter error * fix: empty * test: [skip ci] * fix: remove ';' * feat: improve code --------- Co-authored-by: chenos <chenlinxh@gmail.com>
105 lines
2.6 KiB
TypeScript
105 lines
2.6 KiB
TypeScript
import path from 'path';
|
|
|
|
import { InstallOptions, Plugin } from '@nocobase/server';
|
|
|
|
export class ShopPlugin extends Plugin {
|
|
beforeLoad() {
|
|
// TODO
|
|
}
|
|
|
|
async load() {
|
|
await this.db.import({
|
|
directory: path.resolve(__dirname, 'collections'),
|
|
});
|
|
|
|
this.app.resource({
|
|
name: 'orders',
|
|
actions: {
|
|
create: {
|
|
blacklist: ['id', 'totalPrice', 'status', 'createdAt', 'updatedAt'],
|
|
values: {
|
|
status: 0,
|
|
},
|
|
middlewares: [
|
|
async (ctx, next) => {
|
|
const { productId } = ctx.action.params.values;
|
|
|
|
const product = await ctx.db.getRepository('products').findOne({
|
|
filterByTk: productId,
|
|
filter: {
|
|
enabled: true,
|
|
inventory: {
|
|
$gt: 0,
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!product) {
|
|
return ctx.throw(404);
|
|
}
|
|
|
|
ctx.state.product = product;
|
|
|
|
await next();
|
|
},
|
|
],
|
|
async handler(ctx, next) {
|
|
const { product } = ctx.state;
|
|
const order = await ctx.db.getRepository('orders').create({
|
|
values: {
|
|
...ctx.action.params.values,
|
|
productId: product.id,
|
|
quantity: 1,
|
|
totalPrice: product.price,
|
|
},
|
|
});
|
|
|
|
ctx.body = order;
|
|
},
|
|
},
|
|
list: {
|
|
filter: {
|
|
// TODO: 该操作符已废弃,该处代码需要重构
|
|
// 由 users 插件扩展的过滤器运算符
|
|
$isCurrentUser: true,
|
|
status: {
|
|
$ne: -1,
|
|
},
|
|
},
|
|
fields: ['id', 'status', 'createdAt', 'updatedAt'],
|
|
},
|
|
async deliver(ctx, next) {
|
|
const { filterByTk } = ctx.action.params;
|
|
const orderRepo = ctx.db.getRepository('orders');
|
|
|
|
const [order] = await orderRepo.update({
|
|
filterByTk,
|
|
values: {
|
|
status: 2,
|
|
delivery: {
|
|
...ctx.action.params.values,
|
|
status: 0,
|
|
},
|
|
},
|
|
});
|
|
order.delivery = await order.getDelivery();
|
|
|
|
ctx.body = order;
|
|
|
|
next();
|
|
},
|
|
},
|
|
});
|
|
|
|
this.app.acl.allow('products', '*');
|
|
this.app.acl.allow('categories', '*');
|
|
this.app.acl.allow('orders', '*');
|
|
}
|
|
|
|
async install(options: InstallOptions) {
|
|
// TODO
|
|
}
|
|
}
|
|
|
|
export default ShopPlugin;
|