fix updates

This commit is contained in:
2024-02-09 13:04:38 +05:30
parent 40933a2713
commit 6ca803d7f2
4 changed files with 1025 additions and 34 deletions

View File

@@ -434,8 +434,10 @@ object PurchaseOrderCtrl {
fun reject(ctx: Context) {
val id = ctx.pathParam("id")
val po = database.find(PurchaseOrder::class.java, id) ?: throw NotFoundResponse("po not found for $id")
po.approvalStatus = ApprovalStatus.REJECTED
po.save()
po.apply {
approvalStatus = ApprovalStatus.REJECTED
save()
}
ctx.json(po).status(HttpStatus.CREATED)
}
@@ -448,6 +450,19 @@ object PurchaseOrderCtrl {
?: throw NotFoundResponse("reference quotation not found for po $id")
ctx.json(quote)
}
fun update(ctx: Context) {
val id = ctx.pathParam("id")
val po = database.find(PurchaseOrder::class.java, id) ?: throw NotFoundResponse("po not found for $id")
val updatedPo = ctx.bodyAsClass<PurchaseOrder>()
po.patchValues(updatedPo)
po.update()
}
fun delete(ctx: Context) {
val id = ctx.pathParam("id")
val po = database.find(PurchaseOrder::class.java, id) ?: throw NotFoundResponse("no po found with id $id")
database.delete(po)
ctx.status(HttpStatus.OK)
}
}
data class ProductSearch(
@@ -481,15 +496,14 @@ object ProductCtrl {
database.save(product)
ctx.json(product).status(HttpStatus.CREATED)
}
fun delete(ctx: Context) {
val id = ctx.pathParam("id")
database.delete(Product::class.java, id)
val prod = database.find(Product::class.java, id) ?: throw NotFoundResponse("no product found with id $id")
database.delete(prod)
ctx.status(HttpStatus.OK)
}
fun patch(ctx: Context) {
val id = ctx.pathParam("id")
val patchValues = ctx.bodyAsClass<Map<String, Any>>()
database.beginTransaction().use {
patchValues.entries.forEach { en ->
@@ -511,7 +525,6 @@ object ProductCtrl {
val updatedProduct = ctx.bodyAsClass<Product>()
product.patchValues(updatedProduct)
product.update()
}
@@ -586,28 +599,18 @@ object QuotationCtrl {
}
ctx.result("Quotes batch created").status(HttpStatus.CREATED)
}
fun delete(ctx: Context) {
val id = ctx.pathParam("id")
val quote = database.find(Quotation::class.java, id) ?: throw NotFoundResponse("quote not found for id $id")
quote.delete()
val quote = database.find(Quotation::class.java, id) ?: throw NotFoundResponse("no quote found with id $id")
database.delete(quote)
ctx.status(HttpStatus.OK)
ctx.result("quote with $id deleted")
}
fun generatePO(ctx: Context) {
//user should be redirected to a po form submission with prefilled values
//create a PO object with values from the quote and then send it as body to vendor/po/create ??
}
fun reqForQuote(ctx: Context) {
val reqForQuoteNum = ctx.pathParam(("rfqNum"))
val rfq = database.find(RequestForQuote::class.java)
.where()
.eq("reqForQuoteNum", reqForQuoteNum)
?: throw NotFoundResponse("request for quote not found for this quotation")
ctx.status(HttpStatus.OK)
ctx.json(rfq)
fun update(ctx: Context) {
val id = ctx.pathParam("id")
val quote = database.find(Quotation::class.java, id) ?: throw NotFoundResponse("quote not found for $id")
val updatedQuote = ctx.bodyAsClass<Quotation>()
quote.patchValues(updatedQuote)
quote.update()
}
}
@@ -629,15 +632,12 @@ object DocumentCtrl {
fun print(ctx: Context) {
//would be handled in the frontend ??
}
fun delete(ctx: Context) {
val id = ctx.pathParam("id")
val doc = database.find(Document::class.java, id) ?: throw NotFoundResponse("no doc found with id $id")
//doc.delete()
val doc = database.find(Document::class.java, id) ?: throw NotFoundResponse("no document found with id $id")
database.delete(doc)
ctx.status(HttpStatus.OK)
ctx.result("document deleted with id $id")
}
fun getWithRefId(ctx: Context) {
//fetches a particular doc (po, quote) with ref id
val refId = ctx.pathParam("refId")
@@ -656,7 +656,7 @@ object VendorCtrl {
val logger = LoggerFactory.getLogger("Vendor")
fun get(ctx: Context) {
val id = ctx.pathParam("id")
val vendor = database.find(Vendor::class.java, id) ?: throw NotFoundResponse("no vendor found with id $id")
val vendor =database.find(Vendor::class.java, id) ?: throw NotFoundResponse("no vendor found with id $id")
ctx.status(HttpStatus.OK)
ctx.json(vendor)
}
@@ -684,9 +684,12 @@ object VendorCtrl {
}
fun update(ctx: Context) {
val id = ctx.pathParam("id")
val vendor = database.find(Vendor::class.java, id) ?: throw NotFoundResponse("vendor not found for $id")
val updatedVendor = ctx.bodyAsClass<Vendor>()
vendor.patchValues(updatedVendor)
vendor.update()
}
fun delete(ctx: Context) {
val id = ctx.pathParam("id")
val vendor = database.find(Vendor::class.java, id) ?: throw NotFoundResponse("no vendor found with id $id")