Skip to content

Commit

Permalink
naming and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
maxwn04 committed Oct 11, 2023
1 parent 2da2b2e commit 7eac2db
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions services/MerchStoreService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,31 +148,37 @@ export default class MerchStoreService {
}

/**
* Verify that items have valid options. An item with variants disabled cannot have multiple
* options, and an item with variants enabled cannot have multiple option types.
* Verify that collections have valid photots.
*/
private static verifyCollectionHasValidPhotos(collection: MerchCollection | MerchandiseCollectionModel) {
if (collection.collectionPhotos.length > Config.file.MAX_COLLECTION_PHOTO_COUNT) {
throw new UserError('Merch items cannot have more than 5 pictures');
}
}

public async createCollectionPhoto(item: Uuid, properties: MerchCollectionPhoto): Promise<PublicMerchCollectionPhoto> {
/**
* Creates a collection photo and assign it the corresponding picture url
* and append the photo to the photos list from merchItem
* @param collection merch collection uuid
* @param properties merch collection photo picture url and position
* @returns created collection photo
*/
public async createCollectionPhoto(collection: Uuid, properties: MerchCollectionPhoto): Promise<PublicMerchCollectionPhoto> {
return this.transactions.readWrite(async (txn) => {
const merchCollection = await Repositories.merchStoreCollection(txn).findByUuid(item);
const merchCollection = await Repositories.merchStoreCollection(txn).findByUuid(collection);
if (!merchCollection) throw new NotFoundError('Merch item not found');

// add to the end
const position = merchCollection.collectionPhotos.length;

const createdPhoto = MerchCollectionPhotoModel.create({ ...properties, position, merchCollection });
const merchStoreItemPhotoRepository = Repositories.merchStoreCollectionPhoto(txn);
const merchStoreCollectionPhotoRepository = Repositories.merchStoreCollectionPhoto(txn);

// verify the result photos array
merchCollection.collectionPhotos.push(createdPhoto);
MerchStoreService.verifyCollectionHasValidPhotos(merchCollection);

const upsertedPhoto = await merchStoreItemPhotoRepository.upsertMerchItemPhoto(createdPhoto);
const upsertedPhoto = await merchStoreCollectionPhotoRepository.upsertMerchItemPhoto(createdPhoto);
return upsertedPhoto.getPublicMerchCollectionPhoto();
});
}
Expand Down

0 comments on commit 7eac2db

Please sign in to comment.