mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 15:07:13 +01:00
use types instead of interfaces
This commit is contained in:
21
db/bill.ts
21
db/bill.ts
@@ -2,12 +2,12 @@ import * as mongoose from 'mongoose'
|
||||
import { BILL_STATUS, MILAGE_TARIFS } from './enums'
|
||||
import { getBillTotal } from '../helpers/bill'
|
||||
|
||||
export interface AdditionalCost {
|
||||
export type AdditionalCost = {
|
||||
name: string
|
||||
value: number
|
||||
}
|
||||
|
||||
export interface Bill {
|
||||
export type Bill = {
|
||||
milageStart: number
|
||||
milageEnd: number
|
||||
milage?: number
|
||||
@@ -16,12 +16,11 @@ export interface Bill {
|
||||
additionalCosts: AdditionalCost[]
|
||||
}
|
||||
|
||||
export interface BillDocument
|
||||
extends Bill,
|
||||
mongoose.SchemaTimestampsConfig,
|
||||
mongoose.Document { }
|
||||
export type BillDocument = Bill &
|
||||
mongoose.SchemaTimestampsConfig &
|
||||
mongoose.Document
|
||||
|
||||
export interface BillModel extends mongoose.Model<BillDocument> { }
|
||||
export type BillModel = mongoose.Model<BillDocument>
|
||||
|
||||
const BillSchema = new mongoose.Schema<BillDocument>(
|
||||
{
|
||||
@@ -29,7 +28,7 @@ const BillSchema = new mongoose.Schema<BillDocument>(
|
||||
type: Number,
|
||||
required: true,
|
||||
validate: {
|
||||
validator: function(v: number): boolean {
|
||||
validator: function (v: number): boolean {
|
||||
const bill = this as BillDocument
|
||||
|
||||
return v <= bill.milageEnd
|
||||
@@ -43,7 +42,7 @@ const BillSchema = new mongoose.Schema<BillDocument>(
|
||||
required: true,
|
||||
|
||||
validate: {
|
||||
validator: function(v: number): boolean {
|
||||
validator: function (v: number): boolean {
|
||||
const bill = this as BillDocument
|
||||
|
||||
return v >= bill.milageStart
|
||||
@@ -77,12 +76,12 @@ const BillSchema = new mongoose.Schema<BillDocument>(
|
||||
}
|
||||
)
|
||||
|
||||
BillSchema.virtual('milage').get(function(): number {
|
||||
BillSchema.virtual('milage').get(function (): number {
|
||||
const bill = this as BillDocument
|
||||
return bill.milageEnd - bill.milageStart
|
||||
})
|
||||
|
||||
BillSchema.virtual('total').get(function(): number {
|
||||
BillSchema.virtual('total').get(function (): number {
|
||||
const bill = this as BillDocument
|
||||
|
||||
return getBillTotal(bill)
|
||||
|
||||
Reference in New Issue
Block a user