Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complex @Property Types #97

Open
Css-IanM opened this issue Aug 30, 2017 · 1 comment
Open

Complex @Property Types #97

Css-IanM opened this issue Aug 30, 2017 · 1 comment
Assignees
Projects
Milestone

Comments

@Css-IanM
Copy link

Could anyone point towards documentation or an example of more complex types?
I'm working on migrating a complex Shopping Cart which I would like to assign sub-document ObjectIDs or some other unique identifier at the scope of the user's cart. An example i'm trying to model for below.
1.) Not sure the best way to handle an object that could be one of two types.
2.) how to specify sub document ObjectIds.
3.) I Imagine for the Endpoint denormalization i have on the line items I will have to just make a constant for that.

export class Cart {
    constructor(
        private userId: string,
        private dateCreated: string,
        private lineItems: Array<CartLineItem>,
        private _id?: string,
    ) { }
...
}

export class CartLineItem {
    constructor(
        private type: string,
        private keys: IndexedItemKeys | ArchivedItemKeys,
        private endpoint: Endpoint,
        private pages: number[],
        private description: string,
        private cost?: number,
        private _id?: string
    ) { }
}

export class IndexedItemKeys {
    constructor(
        private instrument: string,
        private documentName: string
    ) { }
}

export class ArchivedItemKeys {
    constructor(
        private bookReference: string,
        private bookNumber: string,
        private bookSuffix: string,
        private pageNumber: string,
        private pageSuffix: string
    ) { }

}
export class Endpoint {
    constructor(
        private stateId: number,
        private countyId: number,
        private stateAbbrevation: string,
        private url: string,
        private name: string,
        private status: number,
        private hasCreditModule: boolean,
        private hasArchiveModule: boolean,
        private _id?: string,
    ) { }
...
}
// Iridium Schema
@Collection('carts')
export class CartMongoSchema extends Instance<CartDTO, CartMongoSchema> {
    @ObjectID
    _id: string;
    @ObjectID
    userId: string;
    @ObjectID
    endpointId: string;
    @Property(Date)
    dateCreated: Date;
    @Property({
        $required: false,
        $type: [{
            type: String,
            // Not sure best way to handles these as depicted in class above can be of either type
            keys: Object,
            // is an entity from another collection and has an ObjectID.
           // intentional de-normalization.
            endpoint: Object,

            pages: [Number],
            description: String,
            cost: Number,
        }]})
    lineItems: Array<CartLineItem>;
}
@notheotherben
Copy link
Member

Hi Ian, this isn't something currently supported out the box with Iridium's validation framework, that being said, there's no reason you can't add a custom validation plugin which allows you to specify intersect types.

I'm currently in the middle of SREcon and don't have a bunch of free time, but I'll see if I can out something together as part of the 8.x alpha to address this use case (potentially involving a rewrite of the validation framework and adding support for MongoDB native collection validation as part of that).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Version 8.x
  
To do
Development

No branches or pull requests

2 participants