Skip to content

Commit

Permalink
Merge pull request #149 from Kpoke/main
Browse files Browse the repository at this point in the history
fix: planter duplicate bug
  • Loading branch information
Kpoke authored May 23, 2023
2 parents 8118b3b + b09649e commit bc6b429
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
21 changes: 14 additions & 7 deletions server/models/GrowerAccount.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,20 @@ class GrowerAccount {
),
...growerAccountToCreate,
});
const planter = await planterRepository.create({
first_name: createdGrowerAccount.first_name,
last_name: createdGrowerAccount.last_name,
phone: createdGrowerAccount.phone,
email: createdGrowerAccount.email,
grower_account_uuid: createdGrowerAccount.id,
});
let planter;

planter = await planterRepository.findUser(growerAccountToCreate.wallet);

if (!planter) {
planter = await planterRepository.create({
first_name: createdGrowerAccount.first_name,
last_name: createdGrowerAccount.last_name,
phone: createdGrowerAccount.phone,
email: createdGrowerAccount.email,
grower_account_uuid: createdGrowerAccount.id,
});
}

growerAccount = await this._growerAccountRepository.update({
id: createdGrowerAccount.id,
reference_id: planter.id,
Expand Down
10 changes: 10 additions & 0 deletions server/repositories/Legacy/PlanterRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ class LegacyPlanterRepository extends BaseRepository {
this._tableName = 'planter';
this._session = session;
}

async findUser(planter_identifier) {
return this._session
.getDB()
.select()
.table(this._tableName)
.where({ phone: planter_identifier })
.orWhere({ email: planter_identifier })
.first();
}
}

module.exports = LegacyPlanterRepository;

0 comments on commit bc6b429

Please sign in to comment.