Skip to content

Commit

Permalink
refactor: findSharedProfile to use profileLoader
Browse files Browse the repository at this point in the history
  • Loading branch information
brettski committed Nov 29, 2023
1 parent 901a446 commit 5ba9772
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/graphql/resolvers/mutations/shareWithAddBy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import * as Sentry from '@sentry/node';
import { dataSources } from '@thatconference/api';
import memberStore from '../../../dataSources/cloudFirestore/member';
import sharingWithStore from '../../../dataSources/cloudFirestore/sharingWith';
import { findSharedProfile } from '../../../lib/findSharedProfile';
import {
findSharedProfile,
findSharedProfileProfileLoader,
} from '../../../lib/findSharedProfile';

const dlog = debug('that:api:members:mutation:share-with-add-by');
const orderStore = dataSources.cloudFirestore.order;
Expand All @@ -17,6 +20,7 @@ export const fieldResolvers = {
{
dataSources: {
firestore,
profileLoader,
events: { userEvents },
},
user,
Expand Down Expand Up @@ -79,9 +83,10 @@ export const fieldResolvers = {
}
if (addResult.message === null) {
dlog('storeResult %o', storeResult);
const sharedProfile = await findSharedProfile({
const sharedProfile = await findSharedProfileProfileLoader({
memberId: user.sub,
firestore,
profileLoader,
});
userEvents.emit('addNewSharingWith', {
sharingWith,
Expand Down Expand Up @@ -109,6 +114,7 @@ export const fieldResolvers = {
{
dataSources: {
firestore,
profileLoader,
events: { userEvents },
},
user,
Expand Down Expand Up @@ -152,9 +158,10 @@ export const fieldResolvers = {
},
});
dlog('storeResult %o', storeResult);
const sharedProfile = await findSharedProfile({
const sharedProfile = await findSharedProfileProfileLoader({
memberId: user.sub,
firestore,
profileLoader,
});

userEvents.emit('addNewSharingWith', {
Expand Down
24 changes: 24 additions & 0 deletions src/lib/findSharedProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,27 @@ export const findSharedProfile = async ({ memberId, firestore }) => {

return sharedProfile;
};

export const findSharedProfileProfileLoader = async ({
memberId,
firestore,
profileLoader,
}) => {
dlog('finding shared profile for %s (pl)', memberId);
let sharedProfile;
sharedProfile = await sharedProfileStore(firestore).get(memberId);
if (sharedProfile === null) {
const memberRecord = await profileLoader.load(memberId);
if (memberRecord) {
sharedProfile = {
id: memberRecord.id,
firstName: memberRecord.firstName,
lastName: memberRecord.lastName,
email: memberRecord.lastName,
company: memberRecord.company,
};
}
}

return sharedProfile;
};

0 comments on commit 5ba9772

Please sign in to comment.