@chevre/domain
Version:
Chevre Domain Library for Node.js
68 lines (58 loc) • 2.18 kB
text/typescript
// tslint:disable:no-console
import * as mongoose from 'mongoose';
import { chevre } from '../../../../lib/index';
const project = { id: String(process.env.PROJECT_ID) };
const IDENTIFIER = 'xxx';
async function main() {
await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false });
// const eventRepo = await chevre.repository.Event.createInstance(mongoose.connection);
const eventOfferRepo = await chevre.repository.EventOffer.createInstance(mongoose.connection);
let docs = await eventOfferRepo.projectFields(
{
project: { id: { $eq: project.id } },
identifier: { $eq: IDENTIFIER }
},
['availableAtOrFrom', 'identifier', 'itemOffered', 'project', 'validFrom']
);
console.log('docs:', docs);
console.log(docs.length, 'docs found');
if (docs.length > 0) {
await eventOfferRepo.deleteById({
project: { id: docs[0].project.id },
id: docs[0].id
});
console.log('deleted', docs[0].id);
}
await eventOfferRepo.save({
attributes: {
identifier: IDENTIFIER,
project: { id: project.id, typeOf: chevre.factory.organizationType.Project },
typeOf: chevre.factory.offerType.Offer,
itemOffered: {
id: 'xxxxx',
typeOf: chevre.factory.eventType.ScreeningEvent
},
seller: {
id: 'xxxxx',
typeOf: chevre.factory.organizationType.Organization
},
availableAtOrFrom: { id: 'xxx' },
validFrom: new Date(),
validThrough: new Date(),
validForMemberTier: { identifier: 'xxx', typeOf: 'MemberProgramTier' }
}
});
console.log('created.');
docs = await await eventOfferRepo.projectFields(
{
project: { id: { $eq: project.id } },
identifier: { $eq: IDENTIFIER }
},
['availableAtOrFrom', 'identifier', 'itemOffered', 'project', 'validFrom']
);
console.log('docs:', docs);
console.log(docs.length, 'docs found');
}
main()
.then()
.catch(console.error);