Skip to content

Commit

Permalink
add missed record declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
Xziy committed Sep 5, 2024
1 parent e01bcbf commit 3d8dd2c
Show file tree
Hide file tree
Showing 23 changed files with 211 additions and 126 deletions.
9 changes: 4 additions & 5 deletions models/BonusProgram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,10 @@ let attributes = {
};

type attributes = typeof attributes;
interface BonusProgram extends attributes, ORM {}
export default BonusProgram;
export interface BonusProgramRecord extends attributes, ORM {}

let Model = {
beforeCreate(init: BonusProgram, cb: (err?: string) => void) {
beforeCreate(init: BonusProgramRecord, cb: (err?: string) => void) {
if (!init.id) {
init.id = uuid();
}
Expand Down Expand Up @@ -184,7 +183,7 @@ let Model = {
* Returns an array with currently possible bonus programs by order
* @return BonusProgram[]
*/
async getAvailable(): Promise<BonusProgram[]> {
async getAvailable(): Promise<BonusProgramRecord[]> {
return await BonusProgram.find({
where: {
// @ts-ignore TODO: First fix types
Expand All @@ -205,5 +204,5 @@ module.exports = {
};

declare global {
const BonusProgram: typeof Model & ORMModel<BonusProgram, null>;
const BonusProgram: typeof Model & ORMModel<BonusProgramRecord, null>;
}
7 changes: 3 additions & 4 deletions models/City.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ let attributes = {
};

type attributes = typeof attributes;
interface City extends attributes, ORM {}
export default City;
export interface CityRecord extends attributes, ORM {}

let Model = {
beforeCreate(streetInit: any, cb: (err?: string) => void) {
beforeCreate(streetInit: CityRecord, cb: (err?: string) => void) {
if (!streetInit.id) {
streetInit.id = uuid();
}
Expand All @@ -49,5 +48,5 @@ module.exports = {
};

declare global {
const City: typeof Model & ORMModel<City, null>;
const City: typeof Model & ORMModel<CityRecord, null>;
}
8 changes: 7 additions & 1 deletion models/Dish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,13 @@ interface IVirtualFields {
}

type attributes = typeof attributes;

/**
* @deprecated use `DishRecord` instead
*/
interface Dish extends RequiredField<OptionalAll<attributes>, "name" | "price">, IVirtualFields, ORM {}
export interface DishRecord extends RequiredField<OptionalAll<attributes>, "name" | "price">, IVirtualFields, ORM {}

export default Dish;

let Model = {
Expand Down Expand Up @@ -574,5 +580,5 @@ module.exports = {
};

declare global {
const Dish: typeof Model & ORMModel<Dish, "name" | "price">;
const Dish: typeof Model & ORMModel<DishRecord, "name" | "price">;
}
7 changes: 5 additions & 2 deletions models/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,11 +150,14 @@ interface IVirtualFields {
}

type attributes = typeof attributes;
/**
* @deprecated use `GroupRecord` instead
*/
interface Group extends OptionalAll<attributes>, IVirtualFields, ORM {}
export default Group;
export interface GroupRecord extends OptionalAll<attributes>, IVirtualFields, ORM {}

let Model = {
beforeCreate: async function(init: any, cb: (err?: string) => void) {
beforeCreate: async function(init: GroupRecord, cb: (err?: string) => void) {
emitter.emit('core:group-before-create', init);
if (!init.id) {
init.id = uuid();
Expand Down
13 changes: 9 additions & 4 deletions models/Maintenance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,31 @@ let attributes = {
};

type attributes = typeof attributes;

/**
* @deprecated use `MaintenanceRecord` instead
*/
interface Maintenance extends attributes, ORM {}
export interface MaintenanceRecord extends attributes, ORM {}
export default Maintenance;

let Model = {
afterCreate: function (maintenance, cb: (err?: string) => void) {
afterCreate: function (maintenance: MaintenanceRecord, cb: (err?: string) => void) {
checkMaintenance()
cb();
},

afterUpdate: function (maintenance, cb: (err?: string) => void) {
afterUpdate: function (maintenance: MaintenanceRecord, cb: (err?: string) => void) {
checkMaintenance()
cb();
},

afterDestroy: function (maintenance, cb: (err?: string) => void) {
afterDestroy: function (maintenance: MaintenanceRecord, cb: (err?: string) => void) {
checkMaintenance();
cb();
},

beforeCreate: function (maintenance, cb: (err?: string) => void) {
beforeCreate: function (maintenance: { id: string; }, cb: (err?: string) => void) {
if(!maintenance.id){
maintenance.id = uuid();
}
Expand Down
7 changes: 5 additions & 2 deletions models/MediaFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,15 @@ let attributes = {
uploadDate: "string",
};
type attributes = typeof attributes;
/**
* @deprecated use MediaFileRecord
*/
interface MediaFile extends OptionalAll<attributes>, ORM { }

/** @deprecated use `MediaFileRecord` */
export type IMediaFile = OptionalAll<attributes>;
export type MediaFileRecord = OptionalAll<attributes>;

// export default IMediaFile;
export interface MediaFileRecord extends OptionalAll<attributes>, ORM { }

let Model = {
beforeCreate(imageInit: any, cb: (err?: string) => void) {
Expand Down
20 changes: 11 additions & 9 deletions models/OneTimePassword.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,16 @@ let attributes = {
};

type attributes = typeof attributes;

/**
* @deprecated use `OneTimePasswordRecord` instead
*/
interface OneTimePassword extends RequiredField<OptionalAll<attributes>, "login" >, ORM {}
export default OneTimePassword;
export interface OneTimePasswordRecord extends RequiredField<OptionalAll<attributes>, "login" >, ORM {}


let Model = {
beforeCreate(record: any, cb: (err?: string) => void) {
beforeCreate(record: OneTimePasswordRecord, cb: (err?: string) => void) {
if (!record.password) {
record.password = generateOtp();
}
Expand Down Expand Up @@ -64,22 +69,19 @@ module.exports = {
};

declare global {
const OneTimePassword: typeof Model & ORMModel<OneTimePassword, "login" >;
const OneTimePassword: typeof Model & ORMModel<OneTimePasswordRecord, "login" >;
}


function generateOtp() {

if (process.env.NODE_ENV !== "production" && process.env.DEFAULT_OTP){
return process.env.DEFAULT_OTP;
}

var digits = '1234567890';
var otp = ''
let digits = '1234567890';
let otp = ''
for (let i = 0; i < 6; i++) {
otp += digits[Math.floor(Math.random() * 10)];
}


return otp;
}
9 changes: 6 additions & 3 deletions models/Order.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { OrderHelper } from "../libs/helpers/OrderHelper";
import { GroupModifier } from "../interfaces/Modifier";
import { isValue } from "../utils/isValue";
import { or } from "ajv/dist/compile/codegen";

export interface PromotionState {
type: string;
message: string;
Expand Down Expand Up @@ -343,9 +344,11 @@ interface stateFlowInstance {
}

type attributes = typeof attributes & stateFlowInstance;
/**
* @deprecated use `OrderRecord` instead
*/
interface Order extends ORM, OptionalAll<attributes> { }

export default Order;
export interface OrderRecord extends ORM, OptionalAll<attributes> { }

let Model = {
beforeCreate(orderInit: Order, cb: (err?: string) => void) {
Expand Down Expand Up @@ -1752,7 +1755,7 @@ module.exports = {

declare global {
// Typescript export
const Order: typeof Model & ORMModel<Order, null> & StateFlowModel;
const Order: typeof Model & ORMModel<OrderRecord, null> & StateFlowModel;
}

// LOCAL HELPERS
Expand Down
12 changes: 8 additions & 4 deletions models/OrderDish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import ORM from "../interfaces/ORM";
import { ORMModel } from "../interfaces/ORMModel";

import Dish from "../models/Dish";
import Order from "../models/Order";
import {OrderRecord} from "../models/Order";
import { Modifier, OrderModifier } from "../interfaces/Modifier";
import { OptionalAll, RequiredField } from "../interfaces/toolsTS";

Expand Down Expand Up @@ -31,7 +31,7 @@ let attributes = {
/** */
order: {
model: "Order",
} as unknown as Order | any,
} as unknown as OrderRecord | string,

/** Position price*/
itemTotal: "number" as unknown as number,
Expand Down Expand Up @@ -87,8 +87,12 @@ let attributes = {
};

type attributes = typeof attributes;
/**
* @deprecated use `OrderDishRecord` instead
*/
interface OrderDish extends RequiredField<OptionalAll<attributes>, "dish" | "amount" >, ORM {}
export default OrderDish;

export interface OrderDishRecord extends RequiredField<OptionalAll<attributes>, "dish" | "amount" >, ORM {}

let Model = {
};
Expand All @@ -100,5 +104,5 @@ module.exports = {
};

declare global {
const OrderDish: typeof Model & ORMModel<OrderDish, "dish" | "amount">;
const OrderDish: typeof Model & ORMModel<OrderDishRecord, "dish" | "amount">;
}
16 changes: 10 additions & 6 deletions models/PaymentDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,14 @@ let attributes = {
};

type attributes = typeof attributes;
/**
* @deprecated use PaymentDocumentRecord instead
*/
interface PaymentDocument extends OptionalAll<attributes>, ORM {}
export default PaymentDocument;
export interface PaymentDocumentRecord extends OptionalAll<attributes>, ORM {}

let Model = {
beforeCreate(paymentDocumentInit: any, cb: (err?: string) => void) {
beforeCreate(paymentDocumentInit: PaymentDocumentRecord, cb: (err?: string) => void) {
if (!paymentDocumentInit.id) {
paymentDocumentInit.id = uuid();
}
Expand All @@ -119,7 +123,7 @@ let Model = {
emitter.emit("core:payment-document-check", self);
try {
let paymentAdapter: PaymentAdapter = await PaymentMethod.getAdapterById(self.paymentMethod);
let checkedPaymentDocument: PaymentDocument = await paymentAdapter.checkPayment(self);
let checkedPaymentDocument: PaymentDocumentRecord = await paymentAdapter.checkPayment(self);
sails.log.silly("checkedPaymentDocument >> ", checkedPaymentDocument)


Expand Down Expand Up @@ -150,7 +154,7 @@ let Model = {
checkAmount(amount);
await checkOrigin(originModel, originModelId);
await checkPaymentMethod(paymentMethodId);
var id: string = uuid();
let id: string = uuid();
id = id.replace(/-/g, '').toUpperCase();
let payment: Payment = {
id: id,
Expand All @@ -164,7 +168,7 @@ let Model = {

emitter.emit("core:payment-document-before-create", payment);
try {
await PaymentDocument.create(payment as PaymentDocument).fetch();
await PaymentDocument.create(payment as PaymentDocumentRecord).fetch();
} catch (e) {
sails.log.error("Error in paymentAdapter.createPayment :", e);
throw {
Expand Down Expand Up @@ -250,7 +254,7 @@ module.exports = {
};

declare global {
const PaymentDocument: typeof Model & ORMModel<PaymentDocument, null>;
const PaymentDocument: typeof Model & ORMModel<PaymentDocumentRecord, null>;
}

////////////////////////////// LOCAL
Expand Down
18 changes: 11 additions & 7 deletions models/PaymentMethod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import PaymentAdapter from "../adapters/payment/PaymentAdapter";
import { OptionalAll, RequiredField } from "../interfaces/toolsTS";
import { PaymentMethodType } from "../libs/enums/PaymentMethodTypes";

var alivePaymentMethods: {} = {};
let alivePaymentMethods = {} as {[k: string]: PaymentAdapter } ;

interface ExternalPayment {
name: string;
Expand Down Expand Up @@ -58,16 +58,20 @@ let attributes = {
};

type attributes = typeof attributes;
/**
* @deprecated use `PaymentMethodRecord` instead
*/
interface PaymentMethod extends RequiredField<OptionalAll<attributes>, "type" | "adapter" | "enable">, ORM {}
export default PaymentMethod;
export interface PaymentMethodRecord extends RequiredField<OptionalAll<attributes>, "type" | "adapter" | "enable">, ORM {}

let Model = {
/**
* Returns the authority of payment Adapter by the famous name Adapter
* @return PaymentAdapter
* @param adapter
*/
async getAdapter(adapter?: string): Promise<PaymentAdapter> {
var paymentMethod: PaymentMethod;
let paymentMethod: PaymentMethodRecord;
if (!adapter) {
paymentMethod = this;
} else {
Expand All @@ -83,7 +87,7 @@ let Model = {
}
},

beforeCreate: function (paymentMethod, cb: (err?: string) => void) {
beforeCreate: function (paymentMethod: PaymentMethodRecord, cb: (err?: string) => void) {
if (!paymentMethod.id) {
paymentMethod.id = uuid();
}
Expand All @@ -96,7 +100,7 @@ let Model = {
* @return
*/
async isPaymentPromise(paymentMethodId?: string): Promise<boolean> {
var checkingPaymentMethod: PaymentMethod;
let checkingPaymentMethod: PaymentMethodRecord;

if (!paymentMethodId) {
checkingPaymentMethod = this;
Expand Down Expand Up @@ -151,7 +155,7 @@ let Model = {
* Returns an array with possible methods of payment for ORDER
* @return array of types of payments
*/
async getAvailable(): Promise<PaymentMethod[]> {
async getAvailable(): Promise<PaymentMethodRecord[]> {
return await PaymentMethod.find({
where: {
or: [
Expand Down Expand Up @@ -226,5 +230,5 @@ module.exports = {
};

declare global {
const PaymentMethod: typeof Model & ORMModel<PaymentMethod, "type" | "adapter" | "enable">;
const PaymentMethod: typeof Model & ORMModel<PaymentMethodRecord, "type" | "adapter" | "enable">;
}
Loading

0 comments on commit 3d8dd2c

Please sign in to comment.