Creating models

Since we know that there are two main models called User and Order, as described in the swagger file, it is time to create them for our application. To do that, go to the src folder and create a new folder, called model, like so:

order-api/src/model

In the model folder, create two files—one for each model, called user.ts and order.ts. The user.ts file's content is as follows:

'use strict'

export interface User {
id: Number
username: String
firstName: String
lastName: String
email: String
password: String
phone: String
userStatus: Number
}

Now, before we create the Order model, we have to create an enumeration to reflect the OrderStatus options. Create a file called orderStatus.ts in the same folder as the user.ts and order.ts files, with the following content:

'use strict'

export enum OrderStatus {
Placed = 'PLACED',
Approved = 'APPROVED',
Delivered = 'DELIVERED',
}

Then, populate the order.ts file with the following content:

import { OrderStatus } from './orderStatus'

export default interface Order {
id: Number
userId: Number
quantity: Number
shipDate: Date
status: OrderStatus
complete: Boolean
}
Note that, regarding the order.ts file, we are importing other information from orderStatus, which is an enumeration, and are using it as a type on the orderStatus property under the order model.

Your project structure will look similar to the following:

order-api structure after the models have been added

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.86.138