@chevre/domain
Version:
Chevre Domain Library for Node.js
71 lines (70 loc) • 3.28 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ServiceOutputIdentifierRepo = void 0;
const cdigit = require("cdigit");
const moment = require("moment-timezone");
// import { RedisClientType } from 'redis';
// tslint:disable-next-line:no-require-imports no-var-requires
const fpe = require('node-fpe');
// import { createSchema as createSettingSchema, modelName as settingModelName } from './mongoose/schemas/setting';
const transactionNumber_1 = require("./mongoose/schemas/transactionNumber");
const transactionNumberCounter_1 = require("./transactionNumberCounter");
/**
* サービスアウトプット識別子リポジトリ
*/
class ServiceOutputIdentifierRepo {
constructor(params) {
// const { connection } = params;
// this.settingModel = connection.model(settingModelName, createSettingSchema());
this.counterRepo = new transactionNumberCounter_1.TransactionNumberCounterRepo(params);
}
// private static createKey(params: {
// startDate: Date;
// timestamp: string;
// }): string {
// return util.format(
// '%s:%s',
// ServiceOutputIdentifierRepo.REDIS_KEY_PREFIX,
// params.timestamp
// );
// }
/**
* タイムスタンプから発行する
*/
publishByTimestamp(params) {
return __awaiter(this, void 0, void 0, function* () {
const timestamp = moment(params.startDate)
.valueOf()
.toString();
let dataFeedExpires;
const dataFeedIdentifier = timestamp;
let incrReply;
// const useMongoBySettings = await this.useMongoBySettings(params);
dataFeedExpires = moment(params.startDate)
.add(1, 'minute') // ミリ秒でカウントしていくので、予約日時後1分で十分
.toDate();
incrReply = yield this.counterRepo.incrementByMongo({
identifier: dataFeedIdentifier,
includedInDataCatalog: { identifier: transactionNumber_1.DataCatalogIdentifier.serviceOutputIdentifier },
expires: dataFeedExpires
});
let identifier = `${timestamp}${incrReply}`;
// checkdigit
const cd = cdigit.luhn.compute(identifier);
identifier = fpe({ password: cd })
.encrypt(identifier);
identifier = `${cd}${identifier}`;
return identifier;
});
}
}
exports.ServiceOutputIdentifierRepo = ServiceOutputIdentifierRepo;
;