Skip to content

Commit

Permalink
feat(api+admin-react): updated organism -> account resolver in order …
Browse files Browse the repository at this point in the history
…to return multiple user accounts
  • Loading branch information
agarbe committed Jul 12, 2024
1 parent 84e1ce0 commit bbed408
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const organismQuery = graphql(`
query getOrganismForAgencyManagerPage($organismId: ID!) {
organism_getOrganism(id: $organismId) {
id
organismOnAccount {
accounts {
id
firstname
lastname
Expand Down Expand Up @@ -49,7 +49,7 @@ export const useAgencyManagerPage = () => {
}),
});

const account = organismResponse?.organism_getOrganism?.organismOnAccount;
const account = organismResponse?.organism_getOrganism?.accounts?.[0];

return {
account,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const agenciesInfoForConnectedUserQuery = graphql(`
informationsCommerciales {
nom
}
organismOnAccount {
accounts {
id
email
firstname
Expand Down Expand Up @@ -181,10 +181,10 @@ const AgenciesSettingsLayout = ({ children }: { children: ReactNode }) => {
},
items: [
...agencies
.map((a) => a.organismOnAccount)
.map((o) => {
.flatMap((agency) => agency.accounts)
.map((a) => {
return {
text: `${o?.firstname} ${o?.lastname}`,
text: `${a?.firstname} ${a?.lastname}`,
linkProps: {
href: "#",
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { prismaClient } from "../../../prisma/client";

export const getAccountsByOrganismIdAndEmail = ({
organismId,
email,
}: {
organismId: string;
email: string;
}) =>
prismaClient.account.findUnique({
where: { organismId, email },
});

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { prismaClient } from "../../../prisma/client";

export const getAccountsByOrganismId = async ({
organismId,
}: {
organismId: string;
}) =>
prismaClient.organism
.findUnique({
where: { id: organismId },
})
.accounts();
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { getAccountsByOrganismIdAndEmail } from "../../account/features/getAccountByOrganismIdAndEmail";
import { updateAccountById } from "../../account/features/updateAccount";
import { UpdateOrganismAccountInput } from "../organism.types";
import { getAccountByOrganismId } from "./getAccountByOrganismId";

export const updateOrganismAccount = async ({
params: { organismId, accountEmail, accountFirstname, accountLastname },
}: {
params: UpdateOrganismAccountInput;
}) => {
const account = await getAccountByOrganismId({ organismId });
const account = await getAccountsByOrganismIdAndEmail({
organismId,
email: accountEmail,
});

if (!account) {
throw Error("Compte utilisateur non trouvé");
Expand Down
2 changes: 1 addition & 1 deletion packages/reva-api/modules/organism/organism.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Organism {
informationsCommerciales: OrganismInformationsCommerciales
maisonMereAAP: MaisonMereAAP
managedDegrees: [OrganismOnDegree!]!
organismOnAccount: Account
accounts: [Account!]!
domaines: [Domaine!]!
conventionCollectives: [ConventionCollective!]!
llToEarth: String
Expand Down
6 changes: 3 additions & 3 deletions packages/reva-api/modules/organism/organism.resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { createOrganismWithMaisonMereAAP } from "./features/createOrganismWithMa
import { createOrUpdateInformationsCommerciales } from "./features/createOrUpdateInformationsCommerciales";
import { updateOrganismDegreesAndDomaines } from "./features/updateOrganismDegreesAndDomaines";
import { findOrganismOnDegreeByOrganismId } from "./features/findOrganismOnDegreeByOrganismId";
import { getAccountByOrganismId } from "./features/getAccountByOrganismId";
import { getAccountsByOrganismId } from "./features/getAccountsByOrganismId";
import { getAgencesByGestionnaireAccountId } from "./features/getAgencesByGestionnaireAccountId";
import { getLLToEarthFromZip } from "./features/getLLToEarthFromZip";
import { getMaisonMereAAPByGestionnaireAccountId } from "./features/getMaisonMereAAPByGestionnaireAccountId";
Expand Down Expand Up @@ -91,8 +91,8 @@ const unsafeResolvers = {
},
managedDegrees: (organism: Organism) =>
findOrganismOnDegreeByOrganismId({ organismId: organism.id }),
organismOnAccount: ({ id: organismId }: Organism) =>
getAccountByOrganismId({
accounts: ({ id: organismId }: Organism) =>
getAccountsByOrganismId({
organismId,
}),
domaines: ({ id: organismId }: Organism) =>
Expand Down

0 comments on commit bbed408

Please sign in to comment.