refractor code,
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { NotFoundError } from '../../http/errors'
|
||||
import * as repo from './offer.repo'
|
||||
|
||||
export function listOffers(companyId: string, filters: { active?: string; public?: string }) {
|
||||
return repo.findMany(companyId, filters)
|
||||
}
|
||||
|
||||
export function getOffer(id: string, companyId: string) {
|
||||
return repo.findByIdOrThrow(id, companyId)
|
||||
}
|
||||
|
||||
export function createOffer(companyId: string, data: any, vehicleIds: string[]) {
|
||||
return repo.create(companyId, data, vehicleIds)
|
||||
}
|
||||
|
||||
export async function updateOffer(id: string, companyId: string, data: any, vehicleIds?: string[]) {
|
||||
const existing = await repo.findFirst(id, companyId)
|
||||
if (!existing) throw new NotFoundError('Offer not found')
|
||||
return repo.update(id, data, vehicleIds)
|
||||
}
|
||||
|
||||
export function deleteOffer(id: string, companyId: string) {
|
||||
return repo.deleteMany(id, companyId)
|
||||
}
|
||||
|
||||
export function setOfferActive(id: string, companyId: string, isActive: boolean) {
|
||||
return repo.setActive(id, companyId, isActive)
|
||||
}
|
||||
|
||||
export function getOfferStats(id: string, companyId: string) {
|
||||
return repo.getStats(id, companyId)
|
||||
}
|
||||
Reference in New Issue
Block a user