// 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.MembershipService } }); 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 identifier = `CIN${(new Date()).valueOf()}`; const transaction = await chevre.service.assetTransaction.registerService.start({ project: { id: project.id, typeOf: chevre.factory.organizationType.Project }, typeOf: chevre.factory.assetTransactionType.RegisterService, transactionNumber: identifier, agent: { typeOf: chevre.factory.personType.Person, name: 'サンプル決済者名称', id: '' }, expires: moment() .add(1, 'minute') .toDate(), object: [ { typeOf: chevre.factory.offerType.Offer, // 7iri85wk5ggjsmg // id: '7iri85wk5ggf685', id: '7k9f3ht34', itemOffered: { // project: { id: project.id, typeOf: chevre.factory.organizationType.Project }, // typeOf: product.typeOf, id: product.id, pointAward: { // typeOf: chevre.factory.actionType.MoneyTransfer, // description?: string; // recipient?: any; toLocation: { identifier: '72001740002', issuedThrough: { id: 'xxx' } }, recipient: { typeOf: 'Person', name: 'サンプル受取人', id: 'sampleId' } }, serviceOutput: { project: { id: project.id, typeOf: chevre.factory.organizationType.Project }, typeOf: chevre.factory.permit.PermitType.Permit, additionalProperty: [{ name: 'sampleName', value: 'sampleValue' }], name: 'サンプルメンバーシップ', issuedBy: { typeOf: 'MovieTheater', 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, endDate: moment('2020-06-10T00:00:00Z') .toDate() })({ 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);