UNPKG

@sangaman/xud

Version:
33 lines 1.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const enums_1 = require("../../types/enums"); exports.default = (sequelize, DataTypes) => { const attributes = { id: { type: DataTypes.STRING, primaryKey: true }, baseCurrency: { type: DataTypes.STRING, allowNull: false }, quoteCurrency: { type: DataTypes.STRING, allowNull: false }, swapProtocol: { type: DataTypes.ENUM, values: Object.values(enums_1.SwapProtocol), allowNull: false, }, }; const options = { tableName: 'pairs', timestamps: false, }; const Pair = sequelize.define('Pair', attributes, options); Pair.associate = (models) => { models.Pair.belongsTo(models.Currency, { foreignKey: 'baseCurrency', }); models.Pair.belongsTo(models.Currency, { foreignKey: 'quoteCurrency', }); const derivePairId = (pair) => { pair.id = `${pair.baseCurrency}/${pair.quoteCurrency}`; }; models.Pair.beforeBulkCreate(pairs => pairs.forEach(pair => derivePairId(pair))); models.Pair.beforeCreate(pair => derivePairId(pair)); }; return Pair; }; //# sourceMappingURL=Pair.js.map