Browse Source

fix(core): Correctly populate Collections in channel

Michael Bromley 3 năm trước cách đây
mục cha
commit
b42bf1e54e

+ 1 - 2
packages/core/e2e/populate.e2e-spec.ts

@@ -188,8 +188,7 @@ describe('populate() function', () => {
         it('product also assigned to default channel', async () => {
             await adminClient.setChannelToken(E2E_DEFAULT_CHANNEL_TOKEN);
             const { products } = await adminClient.query<GetProductListQuery>(GET_PRODUCT_LIST);
-            expect(products.totalItems).toBe(1);
-            expect(products.items.map(i => i.name).sort()).toEqual(['Model Hand']);
+            expect(products.items.map(i => i.name).includes('Model Hand')).toBe(true);
         });
     });
 });

+ 3 - 2
packages/core/src/cli/populate.ts

@@ -86,15 +86,16 @@ export async function populate<T extends INestApplicationContext>(
         );
         if (importResult.errors && importResult.errors.length) {
             const errorFile = path.join(process.cwd(), 'vendure-import-error.log');
-            console.log(
+            Logger.error(
                 `${importResult.errors.length} errors encountered when importing product data. See: ${errorFile}`,
+                loggerCtx,
             );
             await fs.writeFile(errorFile, importResult.errors.join('\n'));
         }
 
         Logger.info(`Imported ${importResult.imported} products`, loggerCtx);
 
-        await populateCollections(app, initialData);
+        await populateCollections(app, initialData, channel);
     }
 
     Logger.info('Done!', loggerCtx);

+ 8 - 9
packages/core/src/data-import/providers/populator/populator.ts

@@ -65,38 +65,38 @@ export class Populator {
         let zoneMap: ZoneMap;
         try {
             zoneMap = await this.populateCountries(ctx, data.countries);
-        } catch (e) {
+        } catch (e: any) {
             Logger.error(`Could not populate countries`);
             Logger.error(e, 'populator', e.stack);
             throw e;
         }
         try {
             await this.populateTaxRates(ctx, data.taxRates, zoneMap);
-        } catch (e) {
+        } catch (e: any) {
             Logger.error(`Could not populate tax rates`);
             Logger.error(e, 'populator', e.stack);
         }
         try {
             await this.populateShippingMethods(ctx, data.shippingMethods);
-        } catch (e) {
+        } catch (e: any) {
             Logger.error(`Could not populate shipping methods`);
             Logger.error(e, 'populator', e.stack);
         }
         try {
             await this.populatePaymentMethods(ctx, data.paymentMethods);
-        } catch (e) {
+        } catch (e: any) {
             Logger.error(`Could not populate payment methods`);
             Logger.error(e, 'populator', e.stack);
         }
         try {
             await this.setChannelDefaults(zoneMap, data, ctx.channel);
-        } catch (e) {
+        } catch (e: any) {
             Logger.error(`Could not set channel defaults`);
             Logger.error(e, 'populator', e.stack);
         }
         try {
             await this.populateRoles(ctx, data.roles);
-        } catch (e) {
+        } catch (e: any) {
             Logger.error(`Could not populate roles`);
             Logger.error(e, 'populator', e.stack);
         }
@@ -121,9 +121,8 @@ export class Populator {
                 filters = (collectionDef.filters || []).map(filter =>
                     this.processFilterDefinition(filter, allFacetValues),
                 );
-            } catch (e) {
-                // tslint:disable-next-line:no-console
-                console.log(e);
+            } catch (e: any) {
+                Logger.error(e.message);
             }
             const collection = await this.collectionService.create(ctx, {
                 translations: [