Commit 6fbda22c authored by Tsvetelina Yordanova's avatar Tsvetelina Yordanova
Browse files

feat: #60 delete promotion

parent c99a971d
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!`);
		}
	}
}
+3 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import { CustomerDeliveriesPopupPageModule } from 'pages/+customers/customer-del
import { CustomerAddrPopupPageModule } from 'pages/+customers/customer-addr-popup/customer-addr-popup.module';
import { FileUploaderModule } from './file-uploader/file-uploader.module';
import { OrderInfoComponent } from './common/order-info/order-info';
import { ImageTableComponent } from './table-components/image-table';

@NgModule({
	declarations: [
@@ -50,6 +51,7 @@ import { OrderInfoComponent } from './common/order-info/order-info';
		CarrierInfoComponent,
		PhoneComponent,
		UserPhoneComponent,
		ImageTableComponent,
	],
	imports: [
		CommonModule,
@@ -80,6 +82,7 @@ import { OrderInfoComponent } from './common/order-info/order-info';
		AccountComponent,
		LocationComponent,
		PhoneComponent,
		ImageTableComponent,
	],
})
export class ComponentsModule {}
+16 −0
Original line number Diff line number Diff line
import { Component } from '@angular/core';
import { ViewCell } from 'ng2-smart-table';

@Component({
	selector: 'image-table',
	styles: ['img { width: 64px; height: 64px}'],
	template: `
		<span class="image-component">
			<img *ngIf="rowData?.image" [src]="rowData?.image" />
		</span>
	`,
})
export class ImageTableComponent implements ViewCell {
	value: string | number;
	rowData: any;
}
Loading