All files / lib/models Quote.ts

0% Statements 0/11
100% Branches 0/0
0% Functions 0/1
0% Lines 0/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                                                                                           
import * as dynogels from 'drandx-dynogels';
import * as joi from 'joi';
import * as uuid from 'uuid';
import { BaseModel } from './BaseModel';
import { QUOTE_STATUS_ENUM } from './Enums';
import { Product } from './Product';
import { User } from './User';
import { awsConfig, globalConst } from '../config/db/appVariables';
 
dynogels.AWS.config.update(awsConfig);    

export class Quote extends BaseModel {
  public quoteId: string;
  public customerId: string;
  public products: Product[];
  public status: QUOTE_STATUS_ENUM;
  public customerPosition: {
      latitude: number,
      longitude: number
  };
  constructor() {
    super();
    this.quoteId = uuid.v4();
  }
 
  public model: dynogels.Model = dynogels.define(`${globalConst.stage}_quotes`, {
        hashKey: 'quoteId',
        rangeKey: 'customerId',
        timestamps: false,
        schema: {
            quoteId: joi.string(),
            customerId: joi.string(),
            products: joi.array(),
            customerPosition: joi.object(),
            status: joi.string(),
            createdAt: joi.number(),
            updatedAt: joi.number(),
        },
        tableName: `${globalConst.stage}_quotes`,
        indexes: [
            { hashKey: 'customerId', rangeKey: 'createdAt', name: 'customerIndex', type: 'global' },
            { hashKey: 'status', rangeKey: 'updatedAt', name: 'statusIndex', type: 'global' },
            ],
    });
}