All files / lib/models Order.ts

100% Statements 11/11
100% Branches 0/0
100% Functions 1/1
100% Lines 11/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53  1x 1x 1x 1x 1x 1x 1x     1x 1x                                           1x     1x                                
import * as uuid from 'uuid';
import * as dynogels from 'drandx-dynogels';
import * as joi from 'joi';
 
import { BaseModel } from './BaseModel';
import { ORDER_STATUS_ENUM } from './Enums';
import { Product } from './Product';
import { globalConst, awsConfig } from "../config/db/appVariables";
import { User } from './User';
import { Pharmacy } from './Pharmacy';
 
dynogels.AWS.config.update(awsConfig);    
 
export class Order extends BaseModel {
  public id: string;
  public customerId: string;
  public pharmacyId: string;
  public products: Product[];
  public quoteId: string;
  public status: ORDER_STATUS_ENUM;
  public customer: User;
  public pharmacy: Pharmacy;
 
  constructor() {
    super();
    this.id = uuid.v4();
  }
 
  public model: dynogels.Model = dynogels.define(`${globalConst.stage}_orders`, {
    hashKey: 'id',
    rangeKey: 'customerId',
    timestamps: false,
    schema: {
      id: joi.string(),
      customerId: joi.string(),
      quoteId: joi.string(),
      pharmacyId: joi.string(),
      products: joi.array(),
      createdAt: joi.number(),
      updatedAt: joi.number(),
      status: joi.string(),
      customer: joi.object(),
      pharmacy: joi.object()
    },
    tableName: `${globalConst.stage}_orders`,
    indexes: [
      { hashKey: 'pharmacyId', rangeKey: 'createdAt', type: 'global', name: 'pharmacyId-createdAt-index',},
      { hashKey: 'customerId', rangeKey: 'createdAt', type: 'global', name: 'customerIdIndex'},
    ],
  });
 
}