66} from "./vendor.schema" ;
77import db from "../../db" ;
88import { BackendError } from "../../utils/errors" ;
9- import { ObjectId } from "mongodb" ;
109import { ZodError } from "zod" ;
11- import type { itemType } from "../orders/order.schema" ;
1210import { ulid } from "ulid" ;
1311
1412export async function handleCreateVendor ( c : Context ) {
@@ -47,7 +45,7 @@ export async function handleGetVendorDetails(c: Context) {
4745 const vendorId = c . req . param ( "vendor" ) ;
4846 const vendor = await ( await db ( ) )
4947 . collection < VendorType > ( "vendors" )
50- . findOne ( { _id : new ObjectId ( vendorId ) , isDeleted : false } ) ;
48+ . findOne ( { id : vendorId , isDeleted : false } ) ;
5149 if ( ! vendor ) {
5250 throw new BackendError ( "NOT_FOUND" , { message : "Vendor not found" } ) ;
5351 }
@@ -67,7 +65,7 @@ export async function handleUpdateVendor(c: Context) {
6765 const vendor = await vendorSchema . parseAsync ( body ) ;
6866 const result = await ( await db ( ) )
6967 . collection < VendorType > ( "vendors" )
70- . updateOne ( { _id : new ObjectId ( vendorId ) } , { $set : vendor } ) ;
68+ . updateOne ( { id : vendorId } , { $set : vendor } ) ;
7169 if ( result . matchedCount === 0 ) {
7270 throw new BackendError ( "NOT_FOUND" , { message : "Vendor not found" } ) ;
7371 }
@@ -86,7 +84,7 @@ export async function handleDeleteVendor(c: Context) {
8684 const result = await ( await db ( ) )
8785 . collection < VendorType > ( "vendors" )
8886 . updateOne (
89- { _id : new ObjectId ( vendorId ) } ,
87+ { id : vendorId } ,
9088 { $set : { isDeleted : true , deletedAt : new Date ( ) } } ,
9189 ) ;
9290 if ( result . matchedCount === 0 ) {
@@ -110,7 +108,7 @@ export async function handleCreateVendorItem(c: Context) {
110108
111109 const vendor = await ( await db ( ) )
112110 . collection ( "vendors" )
113- . findOne ( { _id : new ObjectId ( vendorId ) , isDeleted : false } ) ;
111+ . findOne ( { id : vendorId , isDeleted : false } ) ;
114112 if ( ! vendor ) {
115113 throw new BackendError ( "NOT_FOUND" , { message : "Vendor not found" } ) ;
116114 }
@@ -120,10 +118,7 @@ export async function handleCreateVendorItem(c: Context) {
120118
121119 await ( await db ( ) )
122120 . collection ( "vendors" )
123- . updateOne (
124- { _id : new ObjectId ( vendorId ) } ,
125- { $set : { items : vendorItems } } ,
126- ) ;
121+ . updateOne ( { id : vendorId } , { $set : { items : vendorItems } } ) ;
127122
128123 return c . json ( { success : true , data : item } ) ;
129124 } catch ( error ) {
@@ -139,7 +134,7 @@ export async function handleGetVendorItems(c: Context) {
139134 const vendorId = c . req . param ( "vendor" ) ;
140135 const vendor = await ( await db ( ) )
141136 . collection ( "vendors" )
142- . findOne ( { _id : new ObjectId ( vendorId ) , isDeleted : false } ) ;
137+ . findOne ( { id : vendorId , isDeleted : false } ) ;
143138 if ( ! vendor ) {
144139 throw new BackendError ( "NOT_FOUND" , { message : "Vendor not found" } ) ;
145140 }
@@ -157,7 +152,7 @@ export async function handleGetAllVendorItems(c: Context) {
157152 const vendorId = c . req . param ( "vendor" ) ;
158153 const vendor = await ( await db ( ) )
159154 . collection ( "vendors" )
160- . findOne ( { _id : new ObjectId ( vendorId ) , isDeleted : false } ) ;
155+ . findOne ( { id : vendorId , isDeleted : false } ) ;
161156 if ( ! vendor ) {
162157 throw new BackendError ( "NOT_FOUND" , { message : "Vendor not found" } ) ;
163158 }
@@ -179,7 +174,7 @@ export async function handleUpdateVendorItem(c: Context) {
179174 const result = await ( await db ( ) )
180175 . collection ( "vendors" )
181176 . updateOne (
182- { _id : new ObjectId ( vendorId ) , "items.id" : itemId } ,
177+ { id : vendorId , "items.id" : itemId } ,
183178 { $set : { "items.$" : item } } ,
184179 ) ;
185180 if ( result . matchedCount === 0 ) {
0 commit comments