Skip to content

Commit

Permalink
emitter should just emit
Browse files Browse the repository at this point in the history
  • Loading branch information
Xziy committed Apr 27, 2024
1 parent bb947a7 commit 9a8c79e
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 33 deletions.
1 change: 0 additions & 1 deletion libs/AwaitEmitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ export default class AwaitEmitter {
const execHandler = async function () {
const now = new Date();
try {

const result = await handlerResult;
if (!timeoutEnd) {
successEnd = true;
Expand Down
8 changes: 4 additions & 4 deletions models/Order.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ declare let attributes: {
/**
* @deprecated will be rename to `Items` in **v2**
*/
dishes: number[] | OrderDish[];
dishes: OrderDish[] | number[];
paymentMethod: any;
/** */
paymentMethodTitle: string;
Expand Down Expand Up @@ -175,7 +175,7 @@ declare let Model: {
beforeCreate(orderInit: Order, cb: (err?: string) => void): void;
afterCreate(order: Order, cb: (err?: string) => void): Promise<void>;
/** Add a dish into order */
addDish(criteria: CriteriaQuery<Order>, dish: string | Dish, amount: number, modifiers: OrderModifier[], comment: string, addedBy: "user" | "promotion" | "core" | "custom", replace?: boolean, orderDishId?: number): Promise<void>;
addDish(criteria: CriteriaQuery<Order>, dish: Dish | string, amount: number, modifiers: OrderModifier[], comment: string, addedBy: "user" | "promotion" | "core" | "custom", replace?: boolean, orderDishId?: number): Promise<void>;
removeDish(criteria: CriteriaQuery<Order>, dish: OrderDish, amount: number, stack?: boolean): Promise<void>;
setCount(criteria: CriteriaQuery<Order>, dish: OrderDish, amount: number): Promise<void>;
setComment(criteria: CriteriaQuery<Order>, dish: OrderDish, comment: string): Promise<void>;
Expand Down Expand Up @@ -221,7 +221,7 @@ declare let Model: {
state?: string;
concept?: string;
isMixedConcept?: boolean;
dishes?: number[] | OrderDish[];
dishes?: OrderDish[] | number[];
paymentMethod?: any;
paymentMethodTitle?: string;
paid?: boolean;
Expand Down Expand Up @@ -282,7 +282,7 @@ declare let Model: {
*/
countCart(criteria: CriteriaQuery<Order>, isPromoting?: boolean): Promise<Order>;
doPaid(criteria: CriteriaQuery<Order>, paymentDocument: PaymentDocument): Promise<void>;
applyPromotionCode(criteria: CriteriaQuery<Order>, promotionCodeString: string): Promise<Order>;
applyPromotionCode(criteria: CriteriaQuery<Order>, promotionCodeString: string | null): Promise<Order>;
};
declare global {
const Order: typeof Model & ORMModel<Order, null> & StateFlowModel;
Expand Down
13 changes: 2 additions & 11 deletions models/Order.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const uuid_1 = require("uuid");
const decimal_js_1 = __importDefault(require("decimal.js"));
const decimal_js_1 = require("decimal.js");
const phoneValidByMask_1 = require("../libs/phoneValidByMask");
let attributes = {
/** Id */
Expand Down Expand Up @@ -369,13 +366,7 @@ let Model = {
}
}
}
// NOTE: All dishes with modifiers add as an uniq dish
let results = await emitter.emit("core:add-product-before-write", order, dishObj, 15 * 1000);
const resultsCount = results.length;
const successCount = results.filter((r) => r.state === "success").length;
if (resultsCount !== successCount) {
return;
}
await emitter.emit("core:add-product-before-write", order, dishObj, 15 * 1000);
if (replace) {
orderDish = (await OrderDish.update({ id: orderDishId }, {
dish: dishObj.id,
Expand Down
9 changes: 1 addition & 8 deletions models/Order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,14 +486,7 @@ let Model = {

}

// NOTE: All dishes with modifiers add as an uniq dish
let results = await emitter.emit("core:add-product-before-write", order, dishObj, 15 * 1000);
const resultsCount = results.length;
const successCount = results.filter((r) => r.state === "success").length;
if (resultsCount !== successCount) {
return
}

await emitter.emit("core:add-product-before-write", order, dishObj, 15 * 1000);

if (replace) {
orderDish = (
Expand Down
3 changes: 1 addition & 2 deletions models/PaymentDocument.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/// <reference types="node" />
import { ORMModel } from "../interfaces/ORMModel";
import ORM from "../interfaces/ORM";
import { PaymentResponse } from "../interfaces/Payment";
Expand Down Expand Up @@ -73,7 +72,7 @@ declare let Model: {
register: (originModelId: string, originModel: string, amount: number, paymentMethodId: string, backLinkSuccess: string, backLinkFail: string, comment: string, data: any) => Promise<PaymentResponse>;
afterUpdate: (values: PaymentDocument, next: any) => Promise<void>;
/** Payment check cycle*/
processor: (timeout: number) => Promise<NodeJS.Timeout>;
processor: (timeout: number) => Promise<ReturnType<typeof setInterval>>;
};
declare global {
const PaymentDocument: typeof Model & ORMModel<PaymentDocument, null>;
Expand Down
2 changes: 1 addition & 1 deletion models/User.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ declare let Model: {
* @param phone
* @param target
*/
getPhoneString(phone: Phone, target?: "string" | "login" | "print"): Promise<string>;
getPhoneString(phone: Phone, target?: "login" | "print" | "string"): Promise<string>;
/**
* Update user password
*
Expand Down
12 changes: 6 additions & 6 deletions models/UserBonusProgram.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ interface UserBonusProgram extends attributes, ORM {
export default UserBonusProgram;
declare let Model: {
beforeCreate(init: UserBonusProgram, cb: (err?: string) => void): void;
registration(user: string | User, adapterOrId: string): Promise<UserBonusProgram>;
delete(user: string | User, adapterOrId: string): Promise<void>;
syncAll(user: string | User): Promise<void>;
registration(user: User | string, adapterOrId: string): Promise<UserBonusProgram>;
delete(user: User | string, adapterOrId: string): Promise<void>;
syncAll(user: User | string): Promise<void>;
/** Full sync all transaction with external system */
sync(user: string | User, bonusProgram: string | BonusProgram, force?: boolean): Promise<void>;
checkEnoughToSpend(user: string | User, bonusProgram: string | BonusProgram, amount: number): Promise<boolean>;
sumCurrentBalance(user: string | User, bonusProgram: string | BonusProgram): Promise<number>;
sync(user: User | string, bonusProgram: BonusProgram | string, force?: boolean): Promise<void>;
checkEnoughToSpend(user: User | string, bonusProgram: BonusProgram | string, amount: number): Promise<boolean>;
sumCurrentBalance(user: User | string, bonusProgram: BonusProgram | string): Promise<number>;
};
declare global {
const UserBonusProgram: typeof Model & ORMModel<UserBonusProgram, "user" | "bonusProgram">;
Expand Down

0 comments on commit 9a8c79e

Please sign in to comment.