Skip to content
This repository has been archived by the owner on Nov 21, 2020. It is now read-only.

Commit

Permalink
feat(import): added companiesPrimaryNames column in customer import e…
Browse files Browse the repository at this point in the history
…xcel

close #787
  • Loading branch information
batamar committed May 23, 2020
1 parent 3decf6f commit a452a5c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/data/modules/fields/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ export const checkFieldNames = async (type: string, fields: string[]) => {
property.id = fieldObj._id;
}

if (fieldName === 'companiesPrimaryNames') {
property.name = 'companyIds';
property.type = 'companiesPrimaryNames';
}

if (fieldName === 'ownerEmail') {
property.name = 'ownerId';
property.type = 'ownerEmail';
Expand Down
25 changes: 24 additions & 1 deletion src/workers/bulkInsert.worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as mongoose from 'mongoose';
import { Companies, Customers, ImportHistory, Products, Tags, Users } from '../db/models';
import { Companies, Conformities, Customers, ImportHistory, Products, Tags, Users } from '../db/models';
import { graphqlPubsub } from '../pubsub';
import { connect } from './utils';

Expand Down Expand Up @@ -86,6 +86,12 @@ connect().then(async () => {
}
break;

case 'companiesPrimaryNames':
{
doc.companiesPrimaryNames = (value || '').toString().split(',');
}
break;

case 'tag':
{
const tagName = value.toString();
Expand Down Expand Up @@ -128,7 +134,24 @@ connect().then(async () => {

await create(doc, user)
.then(async cocObj => {
if (doc.companiesPrimaryNames && doc.companiesPrimaryNames.length > 0) {
const companies = await Companies.find({ primaryName: { $in: doc.companiesPrimaryNames } }, { _id: 1 });
const companyIds = companies.map(company => company._id);

console.log(doc.companiesPrimaryNames, companyIds);

for (const _id of companyIds) {
await Conformities.addConformity({
mainType: 'customer',
mainTypeId: cocObj._id,
relType: 'company',
relTypeId: _id,
});
}
}

await ImportHistory.updateOne({ _id: importHistoryId }, { $push: { ids: [cocObj._id] } });

// Increasing success count
inc.success++;
})
Expand Down

0 comments on commit a452a5c

Please sign in to comment.