Archived
1
0
Fork 0
This repository has been archived on 2024-02-17. You can view files and clone it, but cannot push or open issues or pull requests.
SOD/models/payment.js
2020-09-11 10:58:12 +02:00

52 lines
1.1 KiB
JavaScript

"use strict";
let maxLength = 80;
function idGen() {
let id = "";
while (id.length < maxLength) {
let tmp = id + Math.random().toString(36).substring(2, 15);
if (tmp.length <= maxLength)
id = tmp;
else
break;
}
return id;
}
const {
Model
} = require("sequelize");
module.exports = (sequelize, DataTypes) => {
class Payment extends Model {
static associate(models) {
Payment.belongsTo(models.Order);
}
}
Payment.init({
shopReference: {
type: DataTypes.STRING(maxLength),
primaryKey: true,
defaultValue: idGen
},
date: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
},
status: {
type: DataTypes.BOOLEAN
},
amount: {
type: DataTypes.INTEGER
},
discount: {
type: DataTypes.INTEGER
},
transactionUuid: {
type: DataTypes.UUID,
}
}, {
sequelize,
modelName: "Payment",
});
return Payment;
};