fast-furniture-util
v1.0.95
Published
This fast furniture node package constians mongoose driver connection, repositories and models
Downloads
27
Readme
README
This fast furniture node package constians mongoose driver connection, repositories and models
Install
npm i fast-furniture-util
Usage
import { AzureFunction, Context, HttpRequest } from '@azure/functions'
import FastFurniture from 'fast-furniture-util'
import errorHandler from '../shared/error'
const { connect, SupplierRepository } = FastFurniture
const httpTrigger: AzureFunction = async function (
context: Context,
req: HttpRequest
): Promise<void> {
await connect(process.env.CosmosDBConnectionString) // Set the Cosmos DB Connection String
.then(async (resp) => {
let supplier_id = req.query.supplier_id
const supplierRepo = new SupplierRepository()
const notes = await supplierRepo.getNotes(supplier_id)
context.res = {
body: { notes },
}
return context.done()
})
.catch((error) => {
errorHandler(400, error, context)
})
}
export default httpTrigger
Repositories
1. SupplierRepository
2. ProductRepository
2. NoteRepository
Functions of each Repositories
SupplierRepository
Save Supplier
const supplierRepo = new SupplierRepository()
const payload = {
supplierId: supplierId,
name: name,
defaultShippingTime: defaultShippingTime,
}
let newSupplier = await supplierRepo.save(payload)
Delete Supplier
const supplierRepo = new SupplierRepository()
const supplierModel = await supplierRepo.delete(_id)
Get All Supplier
const supplierRepo = new SupplierRepository()
const suppliers = await supplierRepo.findAll()
Update Supplier
const supplierRepo = new SupplierRepository()
const payload = {
supplierId: supplierId,
name: name,
defaultShippingTime: defaultShippingTime,
}
const supplier = await supplierRepo.update(_id, payload)
Create Note
const supplierRepo = new SupplierRepository()
const payload = {
title: title,
note: note,
user: user,
}
let supplier = await supplierRepo.addNote(supplier_id, payload)
ProductRepository
Save Product
const productRepo = new ProductRepository()
const payload = {
supplierId: supplierId,
name: name,
defaultShippingTime: defaultShippingTime,
}
let newProduct = await productRepo.save(payload)
Delete Product
const productRepo = new ProductRepository()
const product = await productRepo.delete(_id)
Get All Product
const productRepo = new ProductRepository()
const product = await productRepo.findAll()
Update Product
const productRepo = new ProductRepository()
const payload = {
supplierId: supplierId,
name: name,
defaultShippingTime: defaultShippingTime,
}
const product = await productRepo.update(_id, payload)
NoteRepository
Delete Note
const noteRepo = new NoteRepository()
let note = await noteRepo.remove(_id)
Get Notes
const supplierRepo = new SupplierRepository()
const notes = await supplierRepo.getNotes(supplier_id)
Update Note
const noteRepo = new NoteRepository()
const payload = {
supplier_id: supplier_id,
title: title,
note: note,
user: user,
}
let updatedNote = await noteRepo.update(_id, payload)