refactor: make inventory images the publication source
Remove the temporary listing-level image count from the schema, validation, DTO, and draft contract. Publication now requires the persisted inventory image repository count. Add migration 0009 and update listing tests and implementation status. Verification: npm test passed 62 tests and integration passed 14 tests. No build script is configured in this repository.
This commit is contained in:
@@ -41,7 +41,6 @@ export function createListing({
|
||||
categoryId,
|
||||
conditionId,
|
||||
askingPriceMinor,
|
||||
imageCount,
|
||||
notes,
|
||||
}) {
|
||||
return {
|
||||
@@ -50,7 +49,6 @@ export function createListing({
|
||||
categoryId: requiredText(categoryId, 'Category ID'),
|
||||
conditionId: requiredText(conditionId, 'Condition ID'),
|
||||
askingPriceMinor: requirePositiveMinorUnit(askingPriceMinor, 'Asking price'),
|
||||
imageCount: requirePositiveInteger(imageCount, 'Image count'),
|
||||
status: LISTING_STATUS.DRAFT,
|
||||
...(typeof notes === 'string' && notes.trim().length > 0
|
||||
? { notes: notes.trim() }
|
||||
@@ -122,10 +120,3 @@ function requirePositiveMinorUnit(value, fieldName) {
|
||||
return value;
|
||||
}
|
||||
|
||||
function requirePositiveInteger(value, fieldName) {
|
||||
if (!Number.isInteger(value) || value <= 0) {
|
||||
throw new Error(`${fieldName} must be a positive integer.`);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import { createApplicationError } from '../../../shared/errors/application-error
|
||||
export function createListingService({ listingRepository, inventoryImageRepository }) {
|
||||
return {
|
||||
async create(input) {
|
||||
canPublishListing(input);
|
||||
const listing = createListing(input);
|
||||
return listingRepository.create(listing);
|
||||
},
|
||||
@@ -23,9 +22,7 @@ export function createListingService({ listingRepository, inventoryImageReposito
|
||||
const status = transitionListingStatus(listing.status, nextStatus);
|
||||
|
||||
if (status === 'AVAILABLE') {
|
||||
const imageCount = inventoryImageRepository
|
||||
? await inventoryImageRepository.countByInventoryItemId(listing.inventoryItemId)
|
||||
: listing.imageCount;
|
||||
const imageCount = await inventoryImageRepository.countByInventoryItemId(listing.inventoryItemId);
|
||||
canPublishListing({ ...listing, imageCount });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user