@things-factory/integration-sellercraft 5.0.14 → 6.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-server/controllers/sellercraft/sellercraft.js +6 -6
- package/dist-server/controllers/sellercraft/sellercraft.js.map +1 -1
- package/dist-server/controllers/sellercraft-api/decorators.js +12 -6
- package/dist-server/controllers/sellercraft-api/decorators.js.map +1 -1
- package/dist-server/controllers/sellercraft-api/index.js +2 -2
- package/dist-server/controllers/sellercraft-api/index.js.map +1 -1
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js +5 -3
- package/dist-server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.js.map +1 -1
- package/dist-server/controllers/sellercraft-channel-integration-api/index.js +2 -2
- package/dist-server/controllers/sellercraft-channel-integration-api/index.js.map +1 -1
- package/dist-server/routers/sellercraft-router.js +29 -3
- package/dist-server/routers/sellercraft-router.js.map +1 -1
- package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js +294 -258
- package/dist-server/service/marketplace-channel/marketplace-channel-order-mutation.js.map +1 -1
- package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js +59 -16
- package/dist-server/service/marketplace-channel/marketplace-channel-product-mutation.js.map +1 -1
- package/dist-server/service/marketplace-channel/marketplace-channel.js +8 -4
- package/dist-server/service/marketplace-channel/marketplace-channel.js.map +1 -1
- package/dist-server/service/sellercraft/sellercraft-mutation.js +6 -4
- package/dist-server/service/sellercraft/sellercraft-mutation.js.map +1 -1
- package/dist-server/service/sellercraft/sellercraft-query.js +6 -8
- package/dist-server/service/sellercraft/sellercraft-query.js.map +1 -1
- package/dist-server/service/sellercraft/sellercraft.js +8 -4
- package/dist-server/service/sellercraft/sellercraft.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -16
- package/server/controllers/sellercraft/sellercraft.ts +6 -6
- package/server/controllers/sellercraft-api/decorators.ts +11 -6
- package/server/controllers/sellercraft-api/index.ts +1 -1
- package/server/controllers/sellercraft-channel-integration/apis/ingest-channel-order.ts +5 -3
- package/server/controllers/sellercraft-channel-integration-api/index.ts +1 -1
- package/server/routers/sellercraft-router.ts +45 -4
- package/server/service/marketplace-channel/marketplace-channel-order-mutation.ts +348 -310
- package/server/service/marketplace-channel/marketplace-channel-product-mutation.ts +78 -17
- package/server/service/marketplace-channel/marketplace-channel.ts +4 -0
- package/server/service/sellercraft/sellercraft-mutation.ts +17 -9
- package/server/service/sellercraft/sellercraft-query.ts +7 -8
- package/server/service/sellercraft/sellercraft.ts +5 -1
| @@ -1,33 +1,42 @@ | |
| 1 1 | 
             
            import { Arg, Ctx, Mutation, Resolver } from 'type-graphql'
         | 
| 2 | 
            -
            import { getRepository } from 'typeorm'
         | 
| 3 2 |  | 
| 4 | 
            -
            import { config } from '@things-factory/env'
         | 
| 5 3 | 
             
            import { StoreAPI } from '@things-factory/integration-marketplace'
         | 
| 4 | 
            +
            import { getRepository } from '@things-factory/shell'
         | 
| 6 5 |  | 
| 7 6 | 
             
            import { SHIPPING_TYPE } from '../../constants'
         | 
| 8 7 | 
             
            import { SellercraftChannelIntegrationAPI } from '../../controllers/sellercraft-channel-integration-api'
         | 
| 9 | 
            -
            import { MarketplaceChannel } from './marketplace-channel'
         | 
| 10 8 | 
             
            import { getShops } from '../../utils/tokencraft-util'
         | 
| 9 | 
            +
            import { MarketplaceChannel } from './marketplace-channel'
         | 
| 11 10 |  | 
| 12 11 | 
             
            @Resolver()
         | 
| 13 12 | 
             
            export class MarketplaceChannelOrderMutation {
         | 
| 14 13 | 
             
              @Mutation(returns => Boolean)
         | 
| 15 14 | 
             
              async syncAllMarketplaceChannelOrders(
         | 
| 16 | 
            -
                @Ctx() context:  | 
| 15 | 
            +
                @Ctx() context: ResolverContext,
         | 
| 17 16 | 
             
                @Arg('fromCreatedDate', { nullable: true }) fromCreatedDate?: string,
         | 
| 18 17 | 
             
                @Arg('toCreatedDate', { nullable: true }) toCreatedDate?: string,
         | 
| 19 18 | 
             
                @Arg('fromUpdatedDate', { nullable: true }) fromUpdatedDate?: string,
         | 
| 20 | 
            -
                @Arg('toUpdatedDate', { nullable: true }) toUpdatedDate?: string
         | 
| 19 | 
            +
                @Arg('toUpdatedDate', { nullable: true }) toUpdatedDate?: string,
         | 
| 20 | 
            +
                @Arg('channelId', { nullable: true }) channelId?: string,
         | 
| 21 | 
            +
                @Arg('shopId', { nullable: true }) shopId?: string,
         | 
| 22 | 
            +
                @Arg('airflow', { nullable: true }) airflow?: boolean
         | 
| 21 23 | 
             
              ): Promise<boolean> {
         | 
| 22 | 
            -
                 | 
| 24 | 
            +
                let channels: MarketplaceChannel[] = await getRepository(MarketplaceChannel).find({ where: { isActive: true } })
         | 
| 25 | 
            +
                let errors: any = []
         | 
| 23 26 |  | 
| 24 | 
            -
                 | 
| 27 | 
            +
                if (channelId) {
         | 
| 28 | 
            +
                  channels = channels.filter(channel => channel.channelId == channelId)
         | 
| 29 | 
            +
                }
         | 
| 25 30 |  | 
| 26 31 | 
             
                for (var i = 0; i < channels.length; i++) {
         | 
| 27 32 | 
             
                  try {
         | 
| 28 33 | 
             
                    const channel: MarketplaceChannel = channels[i]
         | 
| 29 34 | 
             
                    let shops: any = await getShops(channel.channelId)
         | 
| 30 35 |  | 
| 36 | 
            +
                    if (shopId) {
         | 
| 37 | 
            +
                      shops = shops.filter(shop => shop.channel_shop_id == shopId)
         | 
| 38 | 
            +
                    }
         | 
| 39 | 
            +
             | 
| 31 40 | 
             
                    for (var j = 0; j < shops.length; j++) {
         | 
| 32 41 | 
             
                      try {
         | 
| 33 42 | 
             
                        var store = {
         | 
| @@ -50,7 +59,7 @@ export class MarketplaceChannelOrderMutation { | |
| 50 59 | 
             
                        let hasMorePage: boolean = true
         | 
| 51 60 | 
             
                        let lastOrderId: string
         | 
| 52 61 | 
             
                        let cursor: string
         | 
| 53 | 
            -
                        var limit: number =  | 
| 62 | 
            +
                        var limit: number = 20
         | 
| 54 63 |  | 
| 55 64 | 
             
                        while (hasMorePage) {
         | 
| 56 65 | 
             
                          const {
         | 
| @@ -67,327 +76,356 @@ export class MarketplaceChannelOrderMutation { | |
| 67 76 | 
             
                            nextCursor: cursor
         | 
| 68 77 | 
             
                          })
         | 
| 69 78 |  | 
| 70 | 
            -
                           | 
| 79 | 
            +
                          var sellercraftStore = { ...store, platform: 'sellercraftChannelIntegration' }
         | 
| 71 80 |  | 
| 72 | 
            -
                           | 
| 73 | 
            -
             | 
| 74 | 
            -
             | 
| 75 | 
            -
             | 
| 81 | 
            +
                          let mappedOrderResult = marketplaceOrders.map(order => {
         | 
| 82 | 
            +
                            let id = store.platform == 'magento' || store.platform == 'shopify' ? order.name : order.orderNo
         | 
| 83 | 
            +
                            let {
         | 
| 84 | 
            +
                              firstName: custFirstName,
         | 
| 85 | 
            +
                              lastName: custLastName,
         | 
| 86 | 
            +
                              orderCreatedAt: createdAt,
         | 
| 87 | 
            +
                              orderUpdatedAt: updatedAt,
         | 
| 88 | 
            +
                              status,
         | 
| 89 | 
            +
                              sellercraftStatus,
         | 
| 90 | 
            +
                              isSOF,
         | 
| 91 | 
            +
                              orderLineList,
         | 
| 92 | 
            +
                              sellercraftDisplayOrderNo
         | 
| 93 | 
            +
                            } = order
         | 
| 76 94 |  | 
| 77 | 
            -
             | 
| 95 | 
            +
                            let {
         | 
| 96 | 
            +
                              first_name: billFirstName,
         | 
| 97 | 
            +
                              last_name: billLastName,
         | 
| 98 | 
            +
                              address_1: billAddress1,
         | 
| 99 | 
            +
                              address_2: billAddress2,
         | 
| 100 | 
            +
                              address_3: billAddress3,
         | 
| 101 | 
            +
                              address_4: billAddress4,
         | 
| 102 | 
            +
                              address_5: billAddress5,
         | 
| 103 | 
            +
                              city: billCity,
         | 
| 104 | 
            +
                              postcode: billPostalCode,
         | 
| 105 | 
            +
                              country: billCountry,
         | 
| 106 | 
            +
                              phone: billPhone1,
         | 
| 107 | 
            +
                              phone_2: billPhone2
         | 
| 108 | 
            +
                            } = order?.billing
         | 
| 78 109 |  | 
| 79 | 
            -
             | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 82 | 
            -
             | 
| 83 | 
            -
             | 
| 84 | 
            -
             | 
| 85 | 
            -
             | 
| 86 | 
            -
             | 
| 87 | 
            -
             | 
| 88 | 
            -
             | 
| 89 | 
            -
             | 
| 110 | 
            +
                            let {
         | 
| 111 | 
            +
                              first_name: shipFirstName,
         | 
| 112 | 
            +
                              last_name: shipLastName,
         | 
| 113 | 
            +
                              address_1: shipAddress1,
         | 
| 114 | 
            +
                              address_2: shipAddress2,
         | 
| 115 | 
            +
                              address_3: shipAddress3,
         | 
| 116 | 
            +
                              address_4: shipAddress4,
         | 
| 117 | 
            +
                              address_5: shipAddress5,
         | 
| 118 | 
            +
                              city: shipCity,
         | 
| 119 | 
            +
                              postcode: shipPostalCode,
         | 
| 120 | 
            +
                              country: shipCountry,
         | 
| 121 | 
            +
                              phone: shipPhone1,
         | 
| 122 | 
            +
                              phone_2: shipPhone2
         | 
| 123 | 
            +
                            } = order.shipping
         | 
| 90 124 |  | 
| 91 | 
            -
             | 
| 92 | 
            -
                            first_name: billFirstName,
         | 
| 93 | 
            -
                            last_name: billLastName,
         | 
| 94 | 
            -
                            address_1: billAddress1,
         | 
| 95 | 
            -
                            address_2: billAddress2,
         | 
| 96 | 
            -
                            address_3: billAddress3,
         | 
| 97 | 
            -
                            address_4: billAddress4,
         | 
| 98 | 
            -
                            address_5: billAddress5,
         | 
| 99 | 
            -
                            city: billCity,
         | 
| 100 | 
            -
                            postcode: billPostalCode,
         | 
| 101 | 
            -
                            country: billCountry,
         | 
| 102 | 
            -
                            phone: billPhone1,
         | 
| 103 | 
            -
                            phone_2: billPhone2
         | 
| 104 | 
            -
                          } = order?.billing
         | 
| 125 | 
            +
                            let orderPackage = order?.orderPackage || {}
         | 
| 105 126 |  | 
| 106 | 
            -
             | 
| 107 | 
            -
             | 
| 108 | 
            -
             | 
| 109 | 
            -
             | 
| 110 | 
            -
             | 
| 111 | 
            -
             | 
| 112 | 
            -
             | 
| 113 | 
            -
             | 
| 114 | 
            -
             | 
| 115 | 
            -
             | 
| 116 | 
            -
             | 
| 117 | 
            -
                            phone: shipPhone1,
         | 
| 118 | 
            -
                            phone_2: shipPhone2
         | 
| 119 | 
            -
                          } = order.shipping
         | 
| 127 | 
            +
                            let orderItems = order.orderItems.map(item => {
         | 
| 128 | 
            +
                              let {
         | 
| 129 | 
            +
                                name: id,
         | 
| 130 | 
            +
                                variationId: variationId,
         | 
| 131 | 
            +
                                slaExpiresAt,
         | 
| 132 | 
            +
                                total,
         | 
| 133 | 
            +
                                totalTax,
         | 
| 134 | 
            +
                                subtotal,
         | 
| 135 | 
            +
                                subtotalTax,
         | 
| 136 | 
            +
                                qty
         | 
| 137 | 
            +
                              } = item
         | 
| 120 138 |  | 
| 121 | 
            -
             | 
| 139 | 
            +
                              return {
         | 
| 140 | 
            +
                                id,
         | 
| 141 | 
            +
                                variationId,
         | 
| 142 | 
            +
                                currency: order.orderShipping.collectionCurrency,
         | 
| 143 | 
            +
                                createdAt: order.orderCreatedAt,
         | 
| 144 | 
            +
                                updatedAt: order.orderUpdatedAt,
         | 
| 145 | 
            +
                                charges: [
         | 
| 146 | 
            +
                                  {
         | 
| 147 | 
            +
                                    name: 'CHARGES_MARKETING',
         | 
| 148 | 
            +
                                    grossAmount: 0,
         | 
| 149 | 
            +
                                    nettAmount: 0
         | 
| 150 | 
            +
                                  },
         | 
| 151 | 
            +
                                  {
         | 
| 152 | 
            +
                                    name: 'CLAIMS_DAMAGE',
         | 
| 153 | 
            +
                                    grossAmount: 0,
         | 
| 154 | 
            +
                                    nettAmount: 0
         | 
| 155 | 
            +
                                  },
         | 
| 156 | 
            +
                                  {
         | 
| 157 | 
            +
                                    name: 'CLAIMS_LOST',
         | 
| 158 | 
            +
                                    grossAmount: 0,
         | 
| 159 | 
            +
                                    nettAmount: 0
         | 
| 160 | 
            +
                                  },
         | 
| 161 | 
            +
                                  {
         | 
| 162 | 
            +
                                    name: 'COMMISSION_PLATFORM',
         | 
| 163 | 
            +
                                    grossAmount: 0,
         | 
| 164 | 
            +
                                    nettAmount: 0
         | 
| 165 | 
            +
                                  },
         | 
| 166 | 
            +
                                  {
         | 
| 167 | 
            +
                                    name: 'DEPOSIT_PRESALE',
         | 
| 168 | 
            +
                                    grossAmount: 0,
         | 
| 169 | 
            +
                                    nettAmount: 0
         | 
| 170 | 
            +
                                  },
         | 
| 171 | 
            +
                                  {
         | 
| 172 | 
            +
                                    name: 'FEE_MISCELLANEOUS',
         | 
| 173 | 
            +
                                    grossAmount: 0,
         | 
| 174 | 
            +
                                    nettAmount: 0
         | 
| 175 | 
            +
                                  },
         | 
| 176 | 
            +
                                  {
         | 
| 177 | 
            +
                                    name: 'FEE_TRANSACTION',
         | 
| 178 | 
            +
                                    grossAmount: 0,
         | 
| 179 | 
            +
                                    nettAmount: 0
         | 
| 180 | 
            +
                                  },
         | 
| 181 | 
            +
                                  {
         | 
| 182 | 
            +
                                    name: 'PRICE_NORMAL_SELLING',
         | 
| 183 | 
            +
                                    grossAmount: total,
         | 
| 184 | 
            +
                                    nettAmount: subtotal
         | 
| 185 | 
            +
                                  },
         | 
| 186 | 
            +
                                  {
         | 
| 187 | 
            +
                                    name: 'PRICE_RECOMMENDED_RETAIL',
         | 
| 188 | 
            +
                                    grossAmount: 0,
         | 
| 189 | 
            +
                                    nettAmount: 0
         | 
| 190 | 
            +
                                  },
         | 
| 191 | 
            +
                                  {
         | 
| 192 | 
            +
                                    name: 'PROMOTIONS_CUSTOMER_RECEIVED',
         | 
| 193 | 
            +
                                    grossAmount: 0,
         | 
| 194 | 
            +
                                    nettAmount: 0
         | 
| 195 | 
            +
                                  },
         | 
| 196 | 
            +
                                  {
         | 
| 197 | 
            +
                                    name: 'PROMOTIONS_REBATE_PLATFORM',
         | 
| 198 | 
            +
                                    grossAmount: 0,
         | 
| 199 | 
            +
                                    nettAmount: 0
         | 
| 200 | 
            +
                                  },
         | 
| 201 | 
            +
                                  {
         | 
| 202 | 
            +
                                    name: 'PROMOTIONS_REBATE_SELLER',
         | 
| 203 | 
            +
                                    grossAmount: 0,
         | 
| 204 | 
            +
                                    nettAmount: 0
         | 
| 205 | 
            +
                                  },
         | 
| 206 | 
            +
                                  {
         | 
| 207 | 
            +
                                    name: 'REVERSAL_CHARGES_MARKETING',
         | 
| 208 | 
            +
                                    grossAmount: 0,
         | 
| 209 | 
            +
                                    nettAmount: 0
         | 
| 210 | 
            +
                                  },
         | 
| 211 | 
            +
                                  {
         | 
| 212 | 
            +
                                    name: 'REVERSAL_COMMISSION',
         | 
| 213 | 
            +
                                    grossAmount: 0,
         | 
| 214 | 
            +
                                    nettAmount: 0
         | 
| 215 | 
            +
                                  },
         | 
| 216 | 
            +
                                  {
         | 
| 217 | 
            +
                                    name: 'REVERSAL_FEE_MISCELLANEOUS',
         | 
| 218 | 
            +
                                    grossAmount: 0,
         | 
| 219 | 
            +
                                    nettAmount: 0
         | 
| 220 | 
            +
                                  },
         | 
| 221 | 
            +
                                  {
         | 
| 222 | 
            +
                                    name: 'REVERSAL_PROMOTIONS_CUSTOMER_RECEIVED',
         | 
| 223 | 
            +
                                    grossAmount: 0,
         | 
| 224 | 
            +
                                    nettAmount: 0
         | 
| 225 | 
            +
                                  },
         | 
| 226 | 
            +
                                  {
         | 
| 227 | 
            +
                                    name: 'REVERSAL_SELLER_RETURN_REFUND_AMOUNT',
         | 
| 228 | 
            +
                                    grossAmount: 0,
         | 
| 229 | 
            +
                                    nettAmount: 0
         | 
| 230 | 
            +
                                  },
         | 
| 231 | 
            +
                                  {
         | 
| 232 | 
            +
                                    name: 'REVERSAL_SHIPPING_CUSTOMER_PAID',
         | 
| 233 | 
            +
                                    grossAmount: 0,
         | 
| 234 | 
            +
                                    nettAmount: 0
         | 
| 235 | 
            +
                                  },
         | 
| 236 | 
            +
                                  {
         | 
| 237 | 
            +
                                    name: 'REVERSAL_SHIPPING_REBATE_PLATFORM',
         | 
| 238 | 
            +
                                    grossAmount: 0,
         | 
| 239 | 
            +
                                    nettAmount: 0
         | 
| 240 | 
            +
                                  },
         | 
| 241 | 
            +
                                  {
         | 
| 242 | 
            +
                                    name: 'REVERSAL_SHIPPING_SELLER_PAID',
         | 
| 243 | 
            +
                                    grossAmount: 0,
         | 
| 244 | 
            +
                                    nettAmount: 0
         | 
| 245 | 
            +
                                  },
         | 
| 246 | 
            +
                                  {
         | 
| 247 | 
            +
                                    name: 'SHIPPING_COST_TOTAL',
         | 
| 248 | 
            +
                                    grossAmount: 0,
         | 
| 249 | 
            +
                                    nettAmount: 0
         | 
| 250 | 
            +
                                  },
         | 
| 251 | 
            +
                                  {
         | 
| 252 | 
            +
                                    name: 'SHIPPING_CUSTOMER_PAID',
         | 
| 253 | 
            +
                                    grossAmount: 0,
         | 
| 254 | 
            +
                                    nettAmount: 0
         | 
| 255 | 
            +
                                  },
         | 
| 256 | 
            +
                                  {
         | 
| 257 | 
            +
                                    name: 'SHIPPING_REBATE_PLATFORM',
         | 
| 258 | 
            +
                                    grossAmount: 0,
         | 
| 259 | 
            +
                                    nettAmount: 0
         | 
| 260 | 
            +
                                  },
         | 
| 261 | 
            +
                                  {
         | 
| 262 | 
            +
                                    name: 'SHIPPING_SELLER_PAID',
         | 
| 263 | 
            +
                                    grossAmount: 0,
         | 
| 264 | 
            +
                                    nettAmount: 0
         | 
| 265 | 
            +
                                  },
         | 
| 266 | 
            +
                                  {
         | 
| 267 | 
            +
                                    name: 'TAXES',
         | 
| 268 | 
            +
                                    grossAmount: totalTax,
         | 
| 269 | 
            +
                                    nettAmount: subtotalTax
         | 
| 270 | 
            +
                                  },
         | 
| 271 | 
            +
                                  {
         | 
| 272 | 
            +
                                    name: 'VOUCHERS_CUSTOMER_RECEIVED',
         | 
| 273 | 
            +
                                    grossAmount: 0,
         | 
| 274 | 
            +
                                    nettAmount: 0
         | 
| 275 | 
            +
                                  },
         | 
| 276 | 
            +
                                  {
         | 
| 277 | 
            +
                                    name: 'VOUCHERS_REBATE_PLATFORM',
         | 
| 278 | 
            +
                                    grossAmount: 0,
         | 
| 279 | 
            +
                                    nettAmount: 0
         | 
| 280 | 
            +
                                  },
         | 
| 281 | 
            +
                                  {
         | 
| 282 | 
            +
                                    name: 'VOUCHERS_REBATE_SELLER',
         | 
| 283 | 
            +
                                    grossAmount: 0,
         | 
| 284 | 
            +
                                    nettAmount: 0
         | 
| 285 | 
            +
                                  }
         | 
| 286 | 
            +
                                ],
         | 
| 287 | 
            +
                                slaExpiresAt,
         | 
| 288 | 
            +
                                qty
         | 
| 289 | 
            +
                              }
         | 
| 290 | 
            +
                            })
         | 
| 122 291 |  | 
| 123 | 
            -
             | 
| 124 | 
            -
                             | 
| 125 | 
            -
                               | 
| 126 | 
            -
             | 
| 127 | 
            -
             | 
| 128 | 
            -
             | 
| 129 | 
            -
             | 
| 130 | 
            -
             | 
| 131 | 
            -
             | 
| 132 | 
            -
             | 
| 133 | 
            -
             | 
| 292 | 
            +
                            let mappedOrderItems = []
         | 
| 293 | 
            +
                            orderItems.map(oi => {
         | 
| 294 | 
            +
                              for (let i = 0; i < oi.qty; i++) {
         | 
| 295 | 
            +
                                let orderLine
         | 
| 296 | 
            +
                                if (orderLineList) {
         | 
| 297 | 
            +
                                  orderLine = orderLineList?.find(ol => ol.sku_id == oi.variationId) || null
         | 
| 298 | 
            +
                                  orderLineList = orderLineList.filter(ol => ol.order_line_id != orderLine.order_line_id)
         | 
| 299 | 
            +
                                }
         | 
| 300 | 
            +
                                mappedOrderItems.push({
         | 
| 301 | 
            +
                                  ...oi,
         | 
| 302 | 
            +
                                  id: orderLine ? orderLine.order_line_id : `${oi.id}-${i + 1}`
         | 
| 303 | 
            +
                                })
         | 
| 304 | 
            +
                              }
         | 
| 305 | 
            +
                            })
         | 
| 134 306 |  | 
| 135 307 | 
             
                            return {
         | 
| 308 | 
            +
                              custFirstName,
         | 
| 309 | 
            +
                              custLastName,
         | 
| 310 | 
            +
                              createdAt,
         | 
| 311 | 
            +
                              updatedAt,
         | 
| 136 312 | 
             
                              id,
         | 
| 137 | 
            -
                               | 
| 138 | 
            -
                               | 
| 139 | 
            -
                               | 
| 140 | 
            -
                               | 
| 141 | 
            -
                               | 
| 142 | 
            -
             | 
| 143 | 
            -
             | 
| 144 | 
            -
             | 
| 145 | 
            -
             | 
| 146 | 
            -
             | 
| 147 | 
            -
             | 
| 148 | 
            -
             | 
| 149 | 
            -
             | 
| 150 | 
            -
             | 
| 151 | 
            -
             | 
| 152 | 
            -
             | 
| 153 | 
            -
             | 
| 154 | 
            -
             | 
| 155 | 
            -
             | 
| 156 | 
            -
             | 
| 157 | 
            -
             | 
| 158 | 
            -
             | 
| 159 | 
            -
             | 
| 160 | 
            -
             | 
| 161 | 
            -
             | 
| 162 | 
            -
             | 
| 163 | 
            -
             | 
| 164 | 
            -
             | 
| 165 | 
            -
             | 
| 166 | 
            -
             | 
| 167 | 
            -
             | 
| 168 | 
            -
             | 
| 169 | 
            -
                                  grossAmount: 0,
         | 
| 170 | 
            -
                                  nettAmount: 0
         | 
| 171 | 
            -
                                },
         | 
| 172 | 
            -
                                {
         | 
| 173 | 
            -
                                  name: 'FEE_TRANSACTION',
         | 
| 174 | 
            -
                                  grossAmount: 0,
         | 
| 175 | 
            -
                                  nettAmount: 0
         | 
| 176 | 
            -
                                },
         | 
| 177 | 
            -
                                {
         | 
| 178 | 
            -
                                  name: 'PRICE_NORMAL_SELLING',
         | 
| 179 | 
            -
                                  grossAmount: total,
         | 
| 180 | 
            -
                                  nettAmount: subtotal
         | 
| 181 | 
            -
                                },
         | 
| 182 | 
            -
                                {
         | 
| 183 | 
            -
                                  name: 'PRICE_RECOMMENDED_RETAIL',
         | 
| 184 | 
            -
                                  grossAmount: 0,
         | 
| 185 | 
            -
                                  nettAmount: 0
         | 
| 186 | 
            -
                                },
         | 
| 187 | 
            -
                                {
         | 
| 188 | 
            -
                                  name: 'PROMOTIONS_CUSTOMER_RECEIVED',
         | 
| 189 | 
            -
                                  grossAmount: 0,
         | 
| 190 | 
            -
                                  nettAmount: 0
         | 
| 191 | 
            -
                                },
         | 
| 192 | 
            -
                                {
         | 
| 193 | 
            -
                                  name: 'PROMOTIONS_REBATE_PLATFORM',
         | 
| 194 | 
            -
                                  grossAmount: 0,
         | 
| 195 | 
            -
                                  nettAmount: 0
         | 
| 196 | 
            -
                                },
         | 
| 197 | 
            -
                                {
         | 
| 198 | 
            -
                                  name: 'PROMOTIONS_REBATE_SELLER',
         | 
| 199 | 
            -
                                  grossAmount: 0,
         | 
| 200 | 
            -
                                  nettAmount: 0
         | 
| 201 | 
            -
                                },
         | 
| 202 | 
            -
                                {
         | 
| 203 | 
            -
                                  name: 'REVERSAL_CHARGES_MARKETING',
         | 
| 204 | 
            -
                                  grossAmount: 0,
         | 
| 205 | 
            -
                                  nettAmount: 0
         | 
| 206 | 
            -
                                },
         | 
| 207 | 
            -
                                {
         | 
| 208 | 
            -
                                  name: 'REVERSAL_COMMISSION',
         | 
| 209 | 
            -
                                  grossAmount: 0,
         | 
| 210 | 
            -
                                  nettAmount: 0
         | 
| 211 | 
            -
                                },
         | 
| 212 | 
            -
                                {
         | 
| 213 | 
            -
                                  name: 'REVERSAL_FEE_MISCELLANEOUS',
         | 
| 214 | 
            -
                                  grossAmount: 0,
         | 
| 215 | 
            -
                                  nettAmount: 0
         | 
| 216 | 
            -
                                },
         | 
| 217 | 
            -
                                {
         | 
| 218 | 
            -
                                  name: 'REVERSAL_PROMOTIONS_CUSTOMER_RECEIVED',
         | 
| 219 | 
            -
                                  grossAmount: 0,
         | 
| 220 | 
            -
                                  nettAmount: 0
         | 
| 221 | 
            -
                                },
         | 
| 222 | 
            -
                                {
         | 
| 223 | 
            -
                                  name: 'REVERSAL_SELLER_RETURN_REFUND_AMOUNT',
         | 
| 224 | 
            -
                                  grossAmount: 0,
         | 
| 225 | 
            -
                                  nettAmount: 0
         | 
| 226 | 
            -
                                },
         | 
| 227 | 
            -
                                {
         | 
| 228 | 
            -
                                  name: 'REVERSAL_SHIPPING_CUSTOMER_PAID',
         | 
| 229 | 
            -
                                  grossAmount: 0,
         | 
| 230 | 
            -
                                  nettAmount: 0
         | 
| 231 | 
            -
                                },
         | 
| 232 | 
            -
                                {
         | 
| 233 | 
            -
                                  name: 'REVERSAL_SHIPPING_REBATE_PLATFORM',
         | 
| 234 | 
            -
                                  grossAmount: 0,
         | 
| 235 | 
            -
                                  nettAmount: 0
         | 
| 236 | 
            -
                                },
         | 
| 237 | 
            -
                                {
         | 
| 238 | 
            -
                                  name: 'REVERSAL_SHIPPING_SELLER_PAID',
         | 
| 239 | 
            -
                                  grossAmount: 0,
         | 
| 240 | 
            -
                                  nettAmount: 0
         | 
| 241 | 
            -
                                },
         | 
| 242 | 
            -
                                {
         | 
| 243 | 
            -
                                  name: 'SHIPPING_COST_TOTAL',
         | 
| 244 | 
            -
                                  grossAmount: 0,
         | 
| 245 | 
            -
                                  nettAmount: 0
         | 
| 246 | 
            -
                                },
         | 
| 247 | 
            -
                                {
         | 
| 248 | 
            -
                                  name: 'SHIPPING_CUSTOMER_PAID',
         | 
| 249 | 
            -
                                  grossAmount: 0,
         | 
| 250 | 
            -
                                  nettAmount: 0
         | 
| 251 | 
            -
                                },
         | 
| 252 | 
            -
                                {
         | 
| 253 | 
            -
                                  name: 'SHIPPING_REBATE_PLATFORM',
         | 
| 254 | 
            -
                                  grossAmount: 0,
         | 
| 255 | 
            -
                                  nettAmount: 0
         | 
| 256 | 
            -
                                },
         | 
| 257 | 
            -
                                {
         | 
| 258 | 
            -
                                  name: 'SHIPPING_SELLER_PAID',
         | 
| 259 | 
            -
                                  grossAmount: 0,
         | 
| 260 | 
            -
                                  nettAmount: 0
         | 
| 261 | 
            -
                                },
         | 
| 262 | 
            -
                                {
         | 
| 263 | 
            -
                                  name: 'TAXES',
         | 
| 264 | 
            -
                                  grossAmount: totalTax,
         | 
| 265 | 
            -
                                  nettAmount: subtotalTax
         | 
| 266 | 
            -
                                },
         | 
| 267 | 
            -
                                {
         | 
| 268 | 
            -
                                  name: 'VOUCHERS_CUSTOMER_RECEIVED',
         | 
| 269 | 
            -
                                  grossAmount: 0,
         | 
| 270 | 
            -
                                  nettAmount: 0
         | 
| 271 | 
            -
                                },
         | 
| 272 | 
            -
                                {
         | 
| 273 | 
            -
                                  name: 'VOUCHERS_REBATE_PLATFORM',
         | 
| 274 | 
            -
                                  grossAmount: 0,
         | 
| 275 | 
            -
                                  nettAmount: 0
         | 
| 276 | 
            -
                                },
         | 
| 277 | 
            -
                                {
         | 
| 278 | 
            -
                                  name: 'VOUCHERS_REBATE_SELLER',
         | 
| 279 | 
            -
                                  grossAmount: 0,
         | 
| 280 | 
            -
                                  nettAmount: 0
         | 
| 281 | 
            -
                                }
         | 
| 282 | 
            -
                              ],
         | 
| 283 | 
            -
                              slaExpiresAt,
         | 
| 284 | 
            -
                              qty
         | 
| 313 | 
            +
                              sellercraftDisplayOrderNo,
         | 
| 314 | 
            +
                              billFirstName,
         | 
| 315 | 
            +
                              billLastName,
         | 
| 316 | 
            +
                              billAddress1: billAddress1?.toString() || shipAddress1?.toString(),
         | 
| 317 | 
            +
                              billAddress2: billAddress2 || shipAddress2,
         | 
| 318 | 
            +
                              billAddress3: billAddress3 || shipAddress3,
         | 
| 319 | 
            +
                              billAddress4: billAddress4 || shipAddress4,
         | 
| 320 | 
            +
                              billAddress5: billAddress5 || shipAddress5,
         | 
| 321 | 
            +
                              billCity: billCity || shipCity,
         | 
| 322 | 
            +
                              billPostalCode: billPostalCode || shipPostalCode,
         | 
| 323 | 
            +
                              billCountry: billCountry || shipCountry,
         | 
| 324 | 
            +
                              billPhone1: billPhone1 || shipPhone1,
         | 
| 325 | 
            +
                              billPhone2: billPhone2 || shipPhone2,
         | 
| 326 | 
            +
                              shipFirstName,
         | 
| 327 | 
            +
                              shipLastName,
         | 
| 328 | 
            +
                              shipAddress1: shipAddress1?.toString(),
         | 
| 329 | 
            +
                              shipAddress2,
         | 
| 330 | 
            +
                              shipAddress3,
         | 
| 331 | 
            +
                              shipAddress4,
         | 
| 332 | 
            +
                              shipAddress5,
         | 
| 333 | 
            +
                              shipCity,
         | 
| 334 | 
            +
                              shipPostalCode,
         | 
| 335 | 
            +
                              shipCountry,
         | 
| 336 | 
            +
                              shipPhone1,
         | 
| 337 | 
            +
                              shipPhone2,
         | 
| 338 | 
            +
                              mappedOrderItems,
         | 
| 339 | 
            +
                              channelShopId,
         | 
| 340 | 
            +
                              organisationId,
         | 
| 341 | 
            +
                              status: sellercraftStatus || status,
         | 
| 342 | 
            +
                              isSOF: isSOF ? isSOF : false,
         | 
| 343 | 
            +
                              orderPackage,
         | 
| 344 | 
            +
                              charges: getOrderCharges(mappedOrderItems)
         | 
| 285 345 | 
             
                            }
         | 
| 286 346 | 
             
                          })
         | 
| 287 347 |  | 
| 288 | 
            -
                           | 
| 289 | 
            -
             | 
| 290 | 
            -
             | 
| 291 | 
            -
             | 
| 292 | 
            -
                                 | 
| 293 | 
            -
             | 
| 294 | 
            -
                              })
         | 
| 295 | 
            -
                            }
         | 
| 296 | 
            -
                          })
         | 
| 297 | 
            -
             | 
| 298 | 
            -
                          return {
         | 
| 299 | 
            -
                            custFirstName,
         | 
| 300 | 
            -
                            custLastName,
         | 
| 301 | 
            -
                            createdAt,
         | 
| 302 | 
            -
                            updatedAt,
         | 
| 303 | 
            -
                            id,
         | 
| 304 | 
            -
                            billFirstName,
         | 
| 305 | 
            -
                            billLastName,
         | 
| 306 | 
            -
                            billAddress1: billAddress1.toString() || shipAddress1.toString(),
         | 
| 307 | 
            -
                            billAddress2: billAddress2 || shipAddress2,
         | 
| 308 | 
            -
                            billAddress3: billAddress3 || shipAddress3,
         | 
| 309 | 
            -
                            billAddress4: billAddress4 || shipAddress4,
         | 
| 310 | 
            -
                            billAddress5: billAddress5 || shipAddress5,
         | 
| 311 | 
            -
                            billCity: billCity || shipCity,
         | 
| 312 | 
            -
                            billPostalCode: billPostalCode || shipPostalCode,
         | 
| 313 | 
            -
                            billCountry: billCountry || shipCountry,
         | 
| 314 | 
            -
                            billPhone1: billPhone1 || shipPhone1,
         | 
| 315 | 
            -
                            billPhone2: billPhone2 || shipPhone2,
         | 
| 316 | 
            -
                            shipFirstName,
         | 
| 317 | 
            -
                            shipLastName,
         | 
| 318 | 
            -
                            shipAddress1: shipAddress1.toString(),
         | 
| 319 | 
            -
                            shipAddress2,
         | 
| 320 | 
            -
                            shipAddress3,
         | 
| 321 | 
            -
                            shipAddress4,
         | 
| 322 | 
            -
                            shipAddress5,
         | 
| 323 | 
            -
                            shipCity,
         | 
| 324 | 
            -
                            shipPostalCode,
         | 
| 325 | 
            -
                            shipCountry,
         | 
| 326 | 
            -
                            shipPhone1,
         | 
| 327 | 
            -
                            shipPhone2,
         | 
| 328 | 
            -
                            mappedOrderItems,
         | 
| 329 | 
            -
                            channelShopId,
         | 
| 330 | 
            -
                            organisationId,
         | 
| 331 | 
            -
                            status: sellercraftStatus || status,
         | 
| 332 | 
            -
                            isSOF: isSOF ? isSOF : false,
         | 
| 333 | 
            -
                            orderPackage,
         | 
| 334 | 
            -
                            charges: getOrderCharges(mappedOrderItems)
         | 
| 335 | 
            -
                          }
         | 
| 336 | 
            -
                        })
         | 
| 337 | 
            -
             | 
| 338 | 
            -
                        if (mappedOrderResult.length > 0) {
         | 
| 339 | 
            -
                          while (mappedOrderResult.length > 0) {
         | 
| 340 | 
            -
                            let spliceResult = mappedOrderResult.splice(
         | 
| 341 | 
            -
                              0,
         | 
| 342 | 
            -
                              mappedOrderResult.length >= 20 ? 20 : mappedOrderResult.length
         | 
| 343 | 
            -
                            )
         | 
| 348 | 
            +
                          if (mappedOrderResult.length > 0) {
         | 
| 349 | 
            +
                            while (mappedOrderResult.length > 0) {
         | 
| 350 | 
            +
                              let spliceResult = mappedOrderResult.splice(
         | 
| 351 | 
            +
                                0,
         | 
| 352 | 
            +
                                mappedOrderResult.length >= 20 ? 20 : mappedOrderResult.length
         | 
| 353 | 
            +
                              )
         | 
| 344 354 |  | 
| 345 | 
            -
             | 
| 346 | 
            -
             | 
| 347 | 
            -
             | 
| 348 | 
            -
             | 
| 349 | 
            -
             | 
| 355 | 
            +
                              try {
         | 
| 356 | 
            +
                                await SellercraftChannelIntegrationAPI.ingestChannelOrder(sellercraftStore, {
         | 
| 357 | 
            +
                                  orders: spliceResult
         | 
| 358 | 
            +
                                })
         | 
| 359 | 
            +
                              } catch (e) {
         | 
| 360 | 
            +
                                errors.push({
         | 
| 361 | 
            +
                                  name: 'Order Ingestion Error',
         | 
| 362 | 
            +
                                  msg: JSON.stringify(e) || {}
         | 
| 363 | 
            +
                                })
         | 
| 364 | 
            +
                              }
         | 
| 350 365 |  | 
| 351 | 
            -
             | 
| 352 | 
            -
             | 
| 353 | 
            -
             | 
| 354 | 
            -
             | 
| 355 | 
            -
             | 
| 356 | 
            -
             | 
| 357 | 
            -
             | 
| 358 | 
            -
             | 
| 359 | 
            -
             | 
| 360 | 
            -
             | 
| 361 | 
            -
             | 
| 362 | 
            -
             | 
| 363 | 
            -
             | 
| 364 | 
            -
             | 
| 365 | 
            -
             | 
| 366 | 
            -
             | 
| 367 | 
            -
             | 
| 368 | 
            -
             | 
| 369 | 
            -
             | 
| 370 | 
            -
             | 
| 371 | 
            -
             | 
| 372 | 
            -
             | 
| 373 | 
            -
             | 
| 374 | 
            -
             | 
| 375 | 
            -
             | 
| 366 | 
            +
                              await Promise.all(
         | 
| 367 | 
            +
                                spliceResult.map(async result => {
         | 
| 368 | 
            +
                                  if (!result?.isSOF && result?.orderPackage?.packageId) {
         | 
| 369 | 
            +
                                    let orderPackage: any = result.orderPackage
         | 
| 370 | 
            +
                                    let newOrderPackage: any = {
         | 
| 371 | 
            +
                                      channelShopId,
         | 
| 372 | 
            +
                                      nativeOrderId: result.id,
         | 
| 373 | 
            +
                                      nativePackageId: orderPackage.packageId,
         | 
| 374 | 
            +
                                      shippingTrackingCode: orderPackage.trackingNumber,
         | 
| 375 | 
            +
                                      shippingTypeValue: orderPackage?.shippingType
         | 
| 376 | 
            +
                                        ? orderPackage.shippingType
         | 
| 377 | 
            +
                                        : SHIPPING_TYPE.DROP_SHIPPING,
         | 
| 378 | 
            +
                                      warehouseCode: SHIPPING_TYPE.DROP_SHIPPING,
         | 
| 379 | 
            +
                                      shipper: {
         | 
| 380 | 
            +
                                        name: orderPackage.shippingProvider,
         | 
| 381 | 
            +
                                        isCodSupported: orderPackage?.isCodSupport ? orderPackage.isCodSupport : false
         | 
| 382 | 
            +
                                      },
         | 
| 383 | 
            +
                                      documents: orderPackage?.orderDocument || [],
         | 
| 384 | 
            +
                                      shipperLastMile: {
         | 
| 385 | 
            +
                                        name: orderPackage.shippingProvider,
         | 
| 386 | 
            +
                                        isCodSupported: orderPackage?.isCodSupport ? orderPackage.isCodSupport : false
         | 
| 387 | 
            +
                                      },
         | 
| 388 | 
            +
                                      orderItemIds: orderPackage?.orderListIdList
         | 
| 389 | 
            +
                                        ? orderPackage.orderListIdList
         | 
| 390 | 
            +
                                        : result.mappedOrderItems.map(orderItem => orderItem.id)
         | 
| 391 | 
            +
                                    }
         | 
| 392 | 
            +
                                    try {
         | 
| 393 | 
            +
                                      await SellercraftChannelIntegrationAPI.ingestChannelOrderPackage(
         | 
| 394 | 
            +
                                        sellercraftStore,
         | 
| 395 | 
            +
                                        newOrderPackage
         | 
| 396 | 
            +
                                      )
         | 
| 397 | 
            +
                                    } catch (e) {
         | 
| 398 | 
            +
                                      errors.push({
         | 
| 399 | 
            +
                                        name: 'Order Package Ingestion Error',
         | 
| 400 | 
            +
                                        msg: JSON.stringify(e) || {}
         | 
| 401 | 
            +
                                      })
         | 
| 402 | 
            +
                                    }
         | 
| 376 403 | 
             
                                  }
         | 
| 377 | 
            -
             | 
| 378 | 
            -
             | 
| 379 | 
            -
             | 
| 380 | 
            -
                                      newOrderPackage
         | 
| 381 | 
            -
                                    )
         | 
| 382 | 
            -
                                  } catch (e) {}
         | 
| 383 | 
            -
                                }
         | 
| 384 | 
            -
                              })
         | 
| 385 | 
            -
                            )
         | 
| 404 | 
            +
                                })
         | 
| 405 | 
            +
                              )
         | 
| 406 | 
            +
                            }
         | 
| 386 407 | 
             
                          }
         | 
| 408 | 
            +
             | 
| 409 | 
            +
                          if (more) page++
         | 
| 410 | 
            +
                          hasMorePage = more
         | 
| 411 | 
            +
                          cursor = nextCursor
         | 
| 387 412 | 
             
                        }
         | 
| 388 | 
            -
                      } catch (e) { | 
| 413 | 
            +
                      } catch (e) {
         | 
| 414 | 
            +
                        errors.push({
         | 
| 415 | 
            +
                          name: 'Order Processing / Mapping Error',
         | 
| 416 | 
            +
                          msg: JSON.stringify(e) || {}
         | 
| 417 | 
            +
                        })
         | 
| 418 | 
            +
                      }
         | 
| 389 419 | 
             
                    }
         | 
| 390 | 
            -
                  } catch (e) { | 
| 420 | 
            +
                  } catch (e) {
         | 
| 421 | 
            +
                    errors.push({
         | 
| 422 | 
            +
                      name: 'Store Error',
         | 
| 423 | 
            +
                      msg: JSON.stringify(e) || {}
         | 
| 424 | 
            +
                    })
         | 
| 425 | 
            +
                  }
         | 
| 426 | 
            +
                }
         | 
| 427 | 
            +
                if (errors.length > 1 && airflow) {
         | 
| 428 | 
            +
                  throw errors
         | 
| 391 429 | 
             
                }
         | 
| 392 430 | 
             
                return true
         | 
| 393 431 | 
             
              }
         |