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

41 lines
888 B
JavaScript
Raw Normal View History

2020-09-10 19:18:42 +02:00
"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.hasOne(models.Order);
}
}
Payment.init({
shopReference: {
type: DataTypes.STRING(maxLength),
primaryKey: true,
defaultValue: idGen
},
date: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW
}
}, {
sequelize,
modelName: "Payment",
});
return Payment;
};