This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Product, IProduct} from './product' | |
import {Order, IOrder} from './order' | |
const main = async () => { | |
// products to insert | |
const productsPayload: IProduct[] = [{name: 'Pokemon', price: 20, stock: 40}, {name: 'Socks', price: 10, stock: 50}] | |
// Inserted products result typed with the interface IProduct | |
const products: IProduct[] = await Product.insertMany(productsPayload) | |
// Order to insert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Schema, model } from 'mongoose' | |
import { IProduct } from './product' | |
// Utility type which you can put in your utils file | |
type ID = Schema.Types.ObjectId | |
export interface IOrder { | |
_id?: ID | |
// Represents the relation between the order and the product | |
productsIds: ID[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Schema, model } from 'mongoose' | |
// Utility type which you can put in your utils file | |
type ID = Schema.Types.ObjectId | |
export interface IProduct { | |
// Optional so it is easier to use when trying to create a new document | |
_id?: ID | |
name: string | |
price: number |