// tslint:disable:no-console import * as moment from 'moment'; import * as mongoose from 'mongoose'; // import * as redis from 'redis'; import { chevre } from '../../../lib/index'; const project = { id: String(process.env.PROJECT_ID) }; // tslint:disable-next-line:max-func-body-length async function main() { // const client = redis.createClient({ // host: process.env.REDIS_HOST, // port: Number(process.env.REDIS_PORT), // password: process.env.REDIS_KEY // }); await mongoose.connect(process.env.MONGOLAB_URI, { autoIndex: false }); const accountRepo = new chevre.repository.Account(mongoose.connection); const offerRepo = new chevre.repository.Offer(mongoose.connection); const offerCatalogRepo = new chevre.repository.OfferCatalog(mongoose.connection); const productRepo = new chevre.repository.Product(mongoose.connection); const serviceOutputRepo = new chevre.repository.ServiceOutput(mongoose.connection); const projectRepo = new chevre.repository.Project(mongoose.connection); // const taskRepo = new chevre.repository.Task(mongoose.connection); const assetTransactionRepo = new chevre.repository.AssetTransaction(mongoose.connection); // プロダクト検索 const products = await productRepo.search({ project: { id: { $eq: project.id } }, typeOf: { $eq: chevre.factory.product.ProductType.PaymentCard } }); console.log(products); const product = products[0]; console.log(product); // オファーカタログ検索 // const offerCatalog = await offerRepo.findOfferCatalogById({ id: product.hasOfferCatalog.id }); // console.log(offerCatalog); // オファー検索 // const offers = await offerRepo.offerModel.find( // { _id: { $in: (offerCatalog.itemListElement).map((e) => e.id) } }, // { // __v: 0, // createdAt: 0, // updatedAt: 0 // } // ) // .exec() // .then((docs) => docs.map((doc) => doc.toObject())); // console.log(offers); // console.log(offers.length, 'offers found'); const transactionNumber = `CIN${(new Date()).valueOf()}`; const identifier = transactionNumber; const accessCode = '123'; const transaction = await chevre.service.assetTransaction.registerService.start({ project: { id: project.id, typeOf: chevre.factory.organizationType.Project }, typeOf: chevre.factory.assetTransactionType.RegisterService, transactionNumber: transactionNumber, agent: { typeOf: chevre.factory.personType.Person, name: 'サンプル決済者名称', id: '' }, expires: moment() .add(1, 'minute') .toDate(), object: [ { typeOf: chevre.factory.offerType.Offer, id: '7k740xps8', itemOffered: { // project: { id: project.id, typeOf: chevre.factory.organizationType.Project }, // typeOf: product.typeOf, id: product.id, serviceOutput: { project: { id: project.id, typeOf: chevre.factory.organizationType.Project }, typeOf: chevre.factory.permit.PermitType.Permit, identifier: `${identifier}00`, accessCode: accessCode, name: 'プリペ' } } } ] })({ account: accountRepo, offer: offerRepo, offerCatalog: offerCatalogRepo, product: productRepo, serviceOutput: serviceOutputRepo, project: projectRepo, assetTransaction: assetTransactionRepo }); console.log(transaction); console.log('transaction started'); await chevre.service.assetTransaction.registerService.confirm({ id: transaction.id })({ assetTransaction: assetTransactionRepo }); console.log('transaction confirmed'); // await chevre.service.assetTransaction.registerProgramMembership.cancel({ // object: { // membershipNumber: membershipNumber // } // })({ // transaction: assetTransactionRepo // }); // console.log('transaction canceled'); } main() .then(() => { console.log('success!'); }) .catch(console.error);