Loading packages/common/src/interfaces/IPromotion.ts +12 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,12 @@ export interface IPromotionCreateObject extends DBCreateObject { */ product: Product; /** * @type {string} * @memberof IPromotionCreateObject */ productId?: string; /** * @type {number} * @memberof IPromotionCreateObject Loading @@ -74,6 +80,12 @@ export interface IPromotionCreateObject extends DBCreateObject { * @memberof IPromotionCreateObject */ warehouse: IWarehouse; /** * @type {string} * @memberof IPromotionCreateObject */ warehouseId?: string; } export interface IPromotion extends IPromotionCreateObject, DBRawObject { Loading packages/core/src/graphql/products/promotions/promotion.resolver.ts +13 −3 Original line number Diff line number Diff line import { Resolver, Query, Mutation } from '@nestjs/graphql'; import { IPromotionCreateObject } from '@ever-platform/common/src/interfaces/IPromotion'; import { PromotionService } from '../../../services/products/PromotionService'; import Promotion from '@ever-platform/common/src/entities/Promotion'; @Resolver('Promotion') export class PromotionResolver { constructor(private readonly _promotionService: PromotionService) {} @Query('promotions') async getPromotions() { return this._promotionService.getAllPromotions(); async getPromotions(_context, { findInput }) { return this._promotionService.getAllPromotions(findInput); } @Mutation() @Mutation('createPromotion') async createPromotion( _, { createInput }: { createInput: IPromotionCreateObject } Loading @@ -36,4 +37,13 @@ export class PromotionResolver { return this._promotionService.removeMultipleByIds(promotionsIds); } @Mutation('updatePromotion') async updatePromotion( _, { id, updateInput }: { id; updateInput } ): Promise<Promotion> { await this._promotionService.throwIfNotExists(id); return this._promotionService.update(id, updateInput); } } packages/core/src/graphql/products/promotions/promotion.types.graphql +11 −4 Original line number Diff line number Diff line Loading @@ -4,11 +4,13 @@ type Promotion { description: [TranslateType] promoPrice: Float warehouse: Warehouse product: Product warehouseId: String productId: String active: Boolean activeFrom: Date activeTo: Date image: String product: Product purchasesCount: Int } Loading @@ -21,7 +23,7 @@ type Product { _id: String! } input PromotionCreateInput { input PromotionInput { title: [TranslateInput] description: [TranslateInput] promoPrice: Float Loading @@ -34,6 +36,10 @@ input PromotionCreateInput { purchasesCount: Int } input PromotionsFindInput { warehouse: String } input WarehouseInput { _id: String } Loading @@ -44,11 +50,12 @@ input TranslateInput { } type Query { promotions: [Promotion] promotions(findInput: PromotionsFindInput): [Promotion] } type Mutation { createPromotion(createInput: PromotionCreateInput): Promotion createPromotion(createInput: PromotionInput): Promotion updatePromotion(id: String, updateInput: PromotionInput): Promotion removePromotion(id: String!): Void removePromotionsByIds(ids: [String!]!): Remove } packages/core/src/services/products/PromotionService.ts +27 −3 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ import { createEverLogger } from '../../helpers/Log'; import Logger from 'bunyan'; import { IPromotionCreateObject } from '@ever-platform/common/src/interfaces/IPromotion'; import { first } from 'rxjs/operators'; import _ = require('lodash'); @injectable() @routerName('promotion') Loading Loading @@ -36,9 +37,32 @@ export class PromotionService extends DBService<Promotion> implements IService { } } async getAllPromotions(): Promise<any[]> { return this.find({ async getAllPromotions(findInput: { warehouse: string }): Promise<any[]> { const warehousePromotions = await this.Model.find({ warehouse: { $eq: findInput.warehouse }, isDeleted: { $eq: false }, }) .select({ title: 1, description: 1, active: 1, promoPrice: 1, activeFrom: 1, activeTo: 1, image: 1, product: 1, warehouse: 1, purchasesCount: 1, }) .lean() .exec(); return _.map(warehousePromotions, (p) => { return { ...p, warehouseId: p.warehouse, productId: p.product, }; }); } Loading @@ -46,7 +70,7 @@ export class PromotionService extends DBService<Promotion> implements IService { const promotion = await this.get(promotionId).pipe(first()).toPromise(); if (!promotion || promotion.isDeleted) { throw Error(`Prmotion with id '${promotionId}' does not exist!`); throw Error(`Promotion with id '${promotionId}' does not exist!`); } } } packages/merchant-tablet-ionic/src/pages/+promotions/promotion-forms/basic-info/basic-info-form.component.ts +1 −1 Original line number Diff line number Diff line Loading @@ -120,7 +120,7 @@ export class BasicInfoFormComponent implements OnInit, OnDestroy { ), activeFrom: this.promotion.activeFrom || new Date(), activeTo: this.promotion.activeTo || null, product: this.promotion.product || null, product: this.promotion.productId || null, }; this.form.patchValue(promotionFormValue); Loading Loading
packages/common/src/interfaces/IPromotion.ts +12 −0 Original line number Diff line number Diff line Loading @@ -53,6 +53,12 @@ export interface IPromotionCreateObject extends DBCreateObject { */ product: Product; /** * @type {string} * @memberof IPromotionCreateObject */ productId?: string; /** * @type {number} * @memberof IPromotionCreateObject Loading @@ -74,6 +80,12 @@ export interface IPromotionCreateObject extends DBCreateObject { * @memberof IPromotionCreateObject */ warehouse: IWarehouse; /** * @type {string} * @memberof IPromotionCreateObject */ warehouseId?: string; } export interface IPromotion extends IPromotionCreateObject, DBRawObject { Loading
packages/core/src/graphql/products/promotions/promotion.resolver.ts +13 −3 Original line number Diff line number Diff line import { Resolver, Query, Mutation } from '@nestjs/graphql'; import { IPromotionCreateObject } from '@ever-platform/common/src/interfaces/IPromotion'; import { PromotionService } from '../../../services/products/PromotionService'; import Promotion from '@ever-platform/common/src/entities/Promotion'; @Resolver('Promotion') export class PromotionResolver { constructor(private readonly _promotionService: PromotionService) {} @Query('promotions') async getPromotions() { return this._promotionService.getAllPromotions(); async getPromotions(_context, { findInput }) { return this._promotionService.getAllPromotions(findInput); } @Mutation() @Mutation('createPromotion') async createPromotion( _, { createInput }: { createInput: IPromotionCreateObject } Loading @@ -36,4 +37,13 @@ export class PromotionResolver { return this._promotionService.removeMultipleByIds(promotionsIds); } @Mutation('updatePromotion') async updatePromotion( _, { id, updateInput }: { id; updateInput } ): Promise<Promotion> { await this._promotionService.throwIfNotExists(id); return this._promotionService.update(id, updateInput); } }
packages/core/src/graphql/products/promotions/promotion.types.graphql +11 −4 Original line number Diff line number Diff line Loading @@ -4,11 +4,13 @@ type Promotion { description: [TranslateType] promoPrice: Float warehouse: Warehouse product: Product warehouseId: String productId: String active: Boolean activeFrom: Date activeTo: Date image: String product: Product purchasesCount: Int } Loading @@ -21,7 +23,7 @@ type Product { _id: String! } input PromotionCreateInput { input PromotionInput { title: [TranslateInput] description: [TranslateInput] promoPrice: Float Loading @@ -34,6 +36,10 @@ input PromotionCreateInput { purchasesCount: Int } input PromotionsFindInput { warehouse: String } input WarehouseInput { _id: String } Loading @@ -44,11 +50,12 @@ input TranslateInput { } type Query { promotions: [Promotion] promotions(findInput: PromotionsFindInput): [Promotion] } type Mutation { createPromotion(createInput: PromotionCreateInput): Promotion createPromotion(createInput: PromotionInput): Promotion updatePromotion(id: String, updateInput: PromotionInput): Promotion removePromotion(id: String!): Void removePromotionsByIds(ids: [String!]!): Remove }
packages/core/src/services/products/PromotionService.ts +27 −3 Original line number Diff line number Diff line Loading @@ -7,6 +7,7 @@ import { createEverLogger } from '../../helpers/Log'; import Logger from 'bunyan'; import { IPromotionCreateObject } from '@ever-platform/common/src/interfaces/IPromotion'; import { first } from 'rxjs/operators'; import _ = require('lodash'); @injectable() @routerName('promotion') Loading Loading @@ -36,9 +37,32 @@ export class PromotionService extends DBService<Promotion> implements IService { } } async getAllPromotions(): Promise<any[]> { return this.find({ async getAllPromotions(findInput: { warehouse: string }): Promise<any[]> { const warehousePromotions = await this.Model.find({ warehouse: { $eq: findInput.warehouse }, isDeleted: { $eq: false }, }) .select({ title: 1, description: 1, active: 1, promoPrice: 1, activeFrom: 1, activeTo: 1, image: 1, product: 1, warehouse: 1, purchasesCount: 1, }) .lean() .exec(); return _.map(warehousePromotions, (p) => { return { ...p, warehouseId: p.warehouse, productId: p.product, }; }); } Loading @@ -46,7 +70,7 @@ export class PromotionService extends DBService<Promotion> implements IService { const promotion = await this.get(promotionId).pipe(first()).toPromise(); if (!promotion || promotion.isDeleted) { throw Error(`Prmotion with id '${promotionId}' does not exist!`); throw Error(`Promotion with id '${promotionId}' does not exist!`); } } }
packages/merchant-tablet-ionic/src/pages/+promotions/promotion-forms/basic-info/basic-info-form.component.ts +1 −1 Original line number Diff line number Diff line Loading @@ -120,7 +120,7 @@ export class BasicInfoFormComponent implements OnInit, OnDestroy { ), activeFrom: this.promotion.activeFrom || new Date(), activeTo: this.promotion.activeTo || null, product: this.promotion.product || null, product: this.promotion.productId || null, }; this.form.patchValue(promotionFormValue); Loading