@@ -13,15 +13,24 @@ import {
1313 addCategory ,
1414 AddCategoryInput ,
1515 addItem ,
16- addItemImage , addItemToPricingStructure , addItemToViewCateogry , addOrUpdatePricingStructures , addOrUpdateRules ,
17- getItemByName , getPricingStructureByName ,
18- getViewCategoryByName , setPrices
16+ addItemImage ,
17+ addItemToPricingStructure ,
18+ addItemToViewCateogry ,
19+ addOrUpdatePricingStructures ,
20+ addOrUpdateRules ,
21+ getGroupByName ,
22+ getItemByName ,
23+ getPricingStructureByName ,
24+ getViewCategoryByName ,
25+ linkPricingStructureWithGroupId ,
26+ setPrices
1927} from "../../service" ;
2028import { Item } from "../../model/item.model" ;
2129import { createNewItem } from "../../shared-utils/ui-item-value-creator.utils" ;
2230import { Rule , ValidateClause } from "../../model/rule.model" ;
2331import { AddOrUpdatePricingStructureInput } from "../../service/pricing-structure.service" ;
2432import { PricingStructure } from "../../model/pricing-structure.model" ;
33+ import { Group , GROUP_ADMIN , GROUP_PARTNER } from "../../model/group.model" ;
2534
2635export const profiles = [ UPDATER_PROFILE_LEEFAHMEE_DATA ] ;
2736
@@ -424,6 +433,17 @@ export const update = async () => {
424433} ;
425434
426435const runImport = async ( ) => {
436+
437+ // find groups
438+ const adminGroup : Group = ( await getGroupByName ( GROUP_ADMIN ) ) ;
439+ checkNotNull ( adminGroup , `Failed to find admin group` ) ;
440+ const partnerGroup : Group = ( await getGroupByName ( GROUP_PARTNER ) ) ;
441+ checkNotNull ( partnerGroup , `Failed to find partner group` ) ;
442+
443+ const adminGroupId : number = adminGroup . id ;
444+ const partnerGroupId : number = partnerGroup . id ;
445+
446+
427447 // create view
428448 const viewName = 'Lee Fah Mee' ;
429449 let view : View = await getViewByName ( viewName ) ;
@@ -481,7 +501,7 @@ const runImport = async () => {
481501 attributes = await getAttributesInView ( view . id ) ;
482502 }
483503
484- // pricing
504+ // pricing structure
485505 const PRICING_STRUCTURE_NAME = `Lee Fah Mee Standard Pricing Structure` ;
486506 const errs : string [ ] = await addOrUpdatePricingStructures ( [ {
487507 id : - 1 , name : PRICING_STRUCTURE_NAME , description : 'Lee Fah Mee collections standard Pricing Structure' , status : "ENABLED" , viewId : view . id
@@ -490,6 +510,12 @@ const runImport = async () => {
490510 const pricingStructure : PricingStructure = await getPricingStructureByName ( view . id , PRICING_STRUCTURE_NAME ) ;
491511 checkNotNull ( pricingStructure , `Failed to find pricing structure ${ pricingStructure } ` ) ;
492512
513+ // link pricing structure to group
514+ const errors1 = await linkPricingStructureWithGroupId ( pricingStructure . id , adminGroupId ) ;
515+ checkErrors ( errors1 , `Failed to link group ${ adminGroup . name } with Id ${ adminGroupId } with pricing structure ${ pricingStructure . id } ` ) ;
516+ const errors2 = await linkPricingStructureWithGroupId ( pricingStructure . id , partnerGroupId ) ;
517+ checkErrors ( errors2 , `Failed to link group ${ partnerGroup . name } with Id ${ partnerGroupId } with pricing structure ${ pricingStructure . id } ` ) ;
518+
493519 // create items & images for all files
494520 const sizeAttribute : Attribute = await getAttributeInViewByName ( view . id , 'Size' ) ;
495521 const cartonAttribute : Attribute = await getAttributeInViewByName ( view . id , 'Carton' ) ;
@@ -544,6 +570,7 @@ const runImport = async () => {
544570 const r : boolean = await addItemToPricingStructure ( view . id , pricingStructure . id , item . id ) ;
545571 checkTrue ( r , `Failed to add item ${ item . name } with id ${ item . id } to pricing structure ${ pricingStructure . name } with id ${ pricingStructure . id } ` ) ;
546572
573+ // set item pricing
547574 const errs2 : string [ ] = await setPrices ( [ {
548575 pricingStructureId : pricingStructure . id ,
549576 item : { price : m . price , itemId : item . id , country : m . country }
0 commit comments