Unverified Commit fbcc8c86 authored by Ruslan Konviser's avatar Ruslan Konviser Committed by GitHub
Browse files

Merge pull request #1205 from ever-co/feat/#60-delete-promotion

Feat/#60 delete promotion
parents f1c58a41 20925310
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -18,4 +18,22 @@ export class PromotionResolver {
	) {
		return this._promotionService.createPromotion(createInput);
	}

	@Mutation()
	async removePromotion(_, { id }: { id: string }): Promise<void> {
		await this._promotionService.throwIfNotExists(id);
		return this._promotionService.remove(id);
	}

	@Mutation()
	async removePromotionsByIds(_, { ids }: { ids: string[] }): Promise<void> {
		const promotions = await this._promotionService.find({
			_id: { $in: ids },
			isDeleted: { $eq: false },
		});

		const promotionsIds = promotions.map((p) => p.id);

		return this._promotionService.removeMultipleByIds(promotionsIds);
	}
}
+2 −0
Original line number Diff line number Diff line
@@ -41,4 +41,6 @@ type Query {

type Mutation {
	createPromotion(createInput: PromotionCreateInput): Promotion
	removePromotion(id: String!): Void
	removePromotionsByIds(ids: [String!]!): Remove
}
+9 −0
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import Promotion from '@modules/server.common/entities/Promotion';
import { createEverLogger } from '../../helpers/Log';
import Logger from 'bunyan';
import { IPromotionCreateObject } from '@ever-platform/common/src/interfaces/IPromotion';
import { first } from 'rxjs/operators';

@injectable()
@routerName('promotion')
@@ -40,4 +41,12 @@ export class PromotionService extends DBService<Promotion> implements IService {
			isDeleted: { $eq: false },
		});
	}

	async throwIfNotExists(promotionId: string) {
		const promotion = await this.get(promotionId).pipe(first()).toPromise();

		if (!promotion || promotion.isDeleted) {
			throw Error(`Prmotion with id '${promotionId}' does not exist!`);
		}
	}
}
+15 −0
Original line number Diff line number Diff line
@@ -168,6 +168,21 @@
				}
			}
		},
		"PROMOTIONS": {
			"PROMOTIONS": "Промоции",
			"BASIC_INFO": "Основна информация",
			"TITLE": "Заглавие",
			"ACTIVE_FROM": "Активна от",
			"ACTIVE_TO": "Активна до",
			"PURCHASES_COUNT": "Брой покупки",
			"IS_ACTIVE": "Активна",
			"SELECT_DATE": "Изберете дата",
			"DESCRIPTION": "Описание",
			"SAVE": "Запази",
			"NEXT": "Нататък",
			"BACK": "Обратно",
			"LANGUAGE": "Език"
		},
		"SELECT LANGUAGE": {
			"USA": "САЩ",
			"ISRAEL": "Израел",
+15 −0
Original line number Diff line number Diff line
@@ -168,6 +168,21 @@
				}
			}
		},
		"PROMOTIONS": {
			"PROMOTIONS": "Промоции",
			"BASIC_INFO": "Основна информация",
			"TITLE": "Заглавие",
			"ACTIVE_FROM": "Активна от",
			"ACTIVE_TO": "Активна до",
			"PURCHASES_COUNT": "Брой покупки",
			"IS_ACTIVE": "Активна",
			"SELECT_DATE": "Изберете дата",
			"DESCRIPTION": "Описание",
			"SAVE": "Запази",
			"NEXT": "Нататък",
			"BACK": "Обратно",
			"LANGUAGE": "Език"
		},
		"SELECT LANGUAGE": {
			"USA": "САЩ",
			"ISRAEL": "Израел",
Loading