diff --git a/back/package-lock.json b/back/package-lock.json index 2d08aa03ccf..5168bb37b13 100644 --- a/back/package-lock.json +++ b/back/package-lock.json @@ -3090,33 +3090,33 @@ "dev": true }, "@prisma/cli": { - "version": "2.11.0", - "resolved": "https://registry.npmjs.org/@prisma/cli/-/cli-2.11.0.tgz", - "integrity": "sha512-RphW+1SPrEKgpuE5RFM0mv3BeVTF8MCRIyBt35Z9Z/E4YI30qgEWfZu6VfsNDarHRsFiJRKC73wx/aMQ2rLp4g==", + "version": "2.13.0", + "resolved": "https://registry.npmjs.org/@prisma/cli/-/cli-2.13.0.tgz", + "integrity": "sha512-1hTj9H6gVIH5J5GPQVfeHiYFxUv09HVoThGr0Z2ds4JkVMRw///ZXll7pQJvaF7DUheg7dCNf+AXvwmpfm75tg==", "dev": true, "requires": { - "@prisma/bar": "0.0.1", - "@prisma/engines": "2.11.0-10.58369335532e47bdcec77a2f1e7c1fb83a463918" + "@prisma/bar": "^0.0.1", + "@prisma/engines": "2.13.0-32.833ab05d2a20e822f6736a39a27de4fc8f6b3e49" } }, "@prisma/client": { - "version": "2.11.0", - "resolved": "https://registry.npmjs.org/@prisma/client/-/client-2.11.0.tgz", - "integrity": "sha512-BF7K/yi5fAnrt7MelQqUueJyl06IGmIxf+7f5RxFSvyO6xZMbOYxhW21kV2wt10mOIS0khQbo0xY6w/8jViJuQ==", + "version": "2.13.0", + "resolved": "https://registry.npmjs.org/@prisma/client/-/client-2.13.0.tgz", + "integrity": "sha512-osu9oRFWYNU3s+khj7D0xn28yGbk9nUWPG6VYDGIisBf0OTDB3STisCa0O0k5rzk1GpdxLiGJaHpqIo40RkMLw==", "requires": { - "@prisma/engines-version": "2.11.0-10.58369335532e47bdcec77a2f1e7c1fb83a463918" + "@prisma/engines-version": "2.13.0-32.833ab05d2a20e822f6736a39a27de4fc8f6b3e49" } }, "@prisma/engines": { - "version": "2.11.0-10.58369335532e47bdcec77a2f1e7c1fb83a463918", - "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-2.11.0-10.58369335532e47bdcec77a2f1e7c1fb83a463918.tgz", - "integrity": "sha512-0WaUybWM7J5zQuG/zYLbV+ZKx9/nzS7Ruu7Y0K2lXJKy3Z9koeVttq+Xt7tVmUX9TLgI1Rwhb9R2e1JMNDWbsw==", + "version": "2.13.0-32.833ab05d2a20e822f6736a39a27de4fc8f6b3e49", + "resolved": "https://registry.npmjs.org/@prisma/engines/-/engines-2.13.0-32.833ab05d2a20e822f6736a39a27de4fc8f6b3e49.tgz", + "integrity": "sha512-BntRdj/uJQMPRXzcYJv80+NtMq+m6f+PIcCTzOUqKerEo53+ynm4bHo2ocLRLS4XtWovGummDlVgZxgWTRhkAw==", "dev": true }, "@prisma/engines-version": { - "version": "2.11.0-10.58369335532e47bdcec77a2f1e7c1fb83a463918", - "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-2.11.0-10.58369335532e47bdcec77a2f1e7c1fb83a463918.tgz", - "integrity": "sha512-qlkW4dKoW1dUnperWPuhFriZ/NTHlsKLhBbebxRa8qMuD3o37SvWIDGLjFOQx1N0Eb4H04rI3XxgjkWLFVlZCw==" + "version": "2.13.0-32.833ab05d2a20e822f6736a39a27de4fc8f6b3e49", + "resolved": "https://registry.npmjs.org/@prisma/engines-version/-/engines-version-2.13.0-32.833ab05d2a20e822f6736a39a27de4fc8f6b3e49.tgz", + "integrity": "sha512-OsToEhPo8OKOW2RmfjrQs1WRWX6omTsrBVMQLYKR7p3ijNBXFjCw9fk4x5xcnLZvADYR/rUIxjEK2YR+r/RK3w==" }, "@protobufjs/aspromise": { "version": "1.1.2", diff --git a/back/package.json b/back/package.json index 8b5d961d7c9..e37b855fb73 100644 --- a/back/package.json +++ b/back/package.json @@ -29,7 +29,7 @@ "@graphql-tools/load-files": "^6.0.15", "@graphql-tools/merge": "^6.0.15", "@pdf-lib/fontkit": "^1.1.0", - "@prisma/client": "^2.11.0", + "@prisma/client": "^2.13.0", "@sentry/integrations": "^5.15.5", "@sentry/node": "^5.15.5", "apollo-server-express": "^2.19.0", @@ -79,7 +79,7 @@ "@graphql-codegen/typescript": "^1.16.3", "@graphql-codegen/typescript-operations": "^1.13.5", "@graphql-codegen/typescript-resolvers": "^1.13.5", - "@prisma/cli": "^2.11.0", + "@prisma/cli": "^2.13.0", "@types/bcrypt": "^3.0.0", "@types/body-parser": "^1.17.1", "@types/connect-redis": "^0.0.14", diff --git a/back/src/__tests__/auth.integration.ts b/back/src/__tests__/auth.integration.ts index a27d0fa970c..f2723f7c855 100644 --- a/back/src/__tests__/auth.integration.ts +++ b/back/src/__tests__/auth.integration.ts @@ -216,12 +216,14 @@ describe("Authentification with token", () => { // should create a new access token to make it revokable // next time this token is used, it will use passport bearer strategy - const accessToken = await prisma.accessToken.findOne({ where: { token } }); + const accessToken = await prisma.accessToken.findUnique({ + where: { token } + }); expect(accessToken).toBeDefined(); expect(accessToken.token).toEqual(token); expect(accessToken.lastUsed).not.toBeNull(); const accessTokenUser = await prisma.accessToken - .findOne({ where: { token } }) + .findUnique({ where: { token } }) .user(); expect(accessTokenUser.id).toEqual(user.id); }); @@ -247,7 +249,9 @@ describe("Authentification with token", () => { }); // should update lastUsed field - const accessToken = await prisma.accessToken.findOne({ where: { token } }); + const accessToken = await prisma.accessToken.findUnique({ + where: { token } + }); expect(accessToken.lastUsed).not.toBeNull(); }); }); diff --git a/back/src/__tests__/factories.integration.ts b/back/src/__tests__/factories.integration.ts index 0c18bef2b37..5e0089ac086 100644 --- a/back/src/__tests__/factories.integration.ts +++ b/back/src/__tests__/factories.integration.ts @@ -30,7 +30,7 @@ describe("Test Factories", () => { test("should create a user with a company", async () => { const { user, company } = await userWithCompanyFactory("ADMIN"); - const usr = await prisma.user.findOne({ + const usr = await prisma.user.findUnique({ where: { id: user.id }, include: { companyAssociations: { @@ -61,7 +61,7 @@ describe("Test Factories", () => { companyTypes: { set: ["TRANSPORTER"] } }); - const usr = await prisma.user.findOne({ + const usr = await prisma.user.findUnique({ where: { id: user.id }, include: { companyAssociations: { @@ -154,7 +154,7 @@ test("should create a transport segment", async () => { expect(newTransportSegment.transporterCompanySiret).toEqual("1234"); //check reverse access const segments = await prisma.form - .findOne({ where: { id: frm.id } }) + .findUnique({ where: { id: frm.id } }) .transportSegments(); expect(segments.length).toEqual(1); }); diff --git a/back/src/__tests__/factories.ts b/back/src/__tests__/factories.ts index 99f8653e3dd..dfe247952d9 100644 --- a/back/src/__tests__/factories.ts +++ b/back/src/__tests__/factories.ts @@ -1,14 +1,11 @@ import { - CompanyCreateInput, CompanyType, Consistence, EmitterType, - FormCreateInput, QuantityType, Status, - TemporaryStorageDetailCreateInput, - UserCreateInput, - UserRole + UserRole, + Prisma } from "@prisma/client"; import { hash } from "bcrypt"; import prisma from "src/prisma"; @@ -17,7 +14,9 @@ import prisma from "src/prisma"; * Create a user with name and email * @param opt: extra parameters */ -export const userFactory = async (opt: Partial = {}) => { +export const userFactory = async ( + opt: Partial = {} +) => { const defaultPassword = await hash("pass", 10); const userIndex = (await prisma.user.count()) + 1; const data = { @@ -54,7 +53,7 @@ function siretify(index) { * @param opt: extram parameters */ export const companyFactory = async ( - companyOpts: Partial = {} + companyOpts: Partial = {} ) => { const opts = companyOpts || {}; const companyIndex = (await prisma.company.count()) + 1; @@ -77,7 +76,7 @@ export const companyFactory = async ( */ export const userWithCompanyFactory = async ( role, - companyOpts: Partial = {} + companyOpts: Partial = {} ) => { const company = await companyFactory(companyOpts); @@ -184,7 +183,7 @@ const formdata = { recipientCompanyName: "WASTE COMPANY" }; -export const tempStorageData: TemporaryStorageDetailCreateInput = { +export const tempStorageData: Prisma.TemporaryStorageDetailCreateInput = { tempStorerQuantityType: "ESTIMATED", tempStorerQuantityReceived: 1, tempStorerWasteAcceptationStatus: "ACCEPTED", @@ -248,7 +247,7 @@ export const formFactory = async ({ opt = {} }: { ownerId: string; - opt?: Partial; + opt?: Partial; }) => { const formParams = { ...formdata, ...opt }; return prisma.form.create({ @@ -265,7 +264,7 @@ export const formWithTempStorageFactory = async ({ opt = {} }: { ownerId: string; - opt?: Partial; + opt?: Partial; }) => { return formFactory({ ownerId, diff --git a/back/src/auth.ts b/back/src/auth.ts index 3de8c01b40b..0ebba400e1e 100644 --- a/back/src/auth.ts +++ b/back/src/auth.ts @@ -61,7 +61,7 @@ passport.use( new LocalStrategy( { usernameField: "email" }, async (username, password, done) => { - const user = await prisma.user.findOne({ + const user = await prisma.user.findUnique({ where: { email: sanitizeEmail(username) } }); @@ -92,7 +92,7 @@ passport.serializeUser((user: User, done) => { passport.deserializeUser((id: string, done) => { prisma.user - .findOne({ where: { id } }) + .findUnique({ where: { id } }) .then(user => done(null, { ...user, auth: AuthType.Session })) .catch(err => done(err)); }); @@ -108,14 +108,14 @@ passport.use( jwtOpts, async (req: express.Request, jwtPayload: { userId: string }, done) => { try { - const user = await prisma.user.findOne({ + const user = await prisma.user.findUnique({ where: { id: jwtPayload.userId } }); if (user) { const token = jwtOpts.jwtFromRequest(req); // verify that the token has not been // converted to OAuth and revoked - const accessToken = await prisma.accessToken.findOne({ + const accessToken = await prisma.accessToken.findUnique({ where: { token } }); if (accessToken && accessToken.isRevoked) { @@ -157,7 +157,7 @@ export function updateAccessTokenLastUsed(accessToken: AccessToken) { passport.use( new BearerStrategy(async (token, done) => { try { - const accessToken = await prisma.accessToken.findOne({ + const accessToken = await prisma.accessToken.findUnique({ where: { token }, include: { user: true } }); @@ -187,7 +187,7 @@ passport.use( */ const verifyClient: VerifyFunction = async (clientId, clientSecret, done) => { - const application = await prisma.application.findOne({ + const application = await prisma.application.findUnique({ where: { id: clientId } }); if (!application) { diff --git a/back/src/common/middlewares/__tests__/loggingMiddleware.test.ts b/back/src/common/middlewares/__tests__/loggingMiddleware.test.ts index 02ee9dcd1c3..a80f4252402 100644 --- a/back/src/common/middlewares/__tests__/loggingMiddleware.test.ts +++ b/back/src/common/middlewares/__tests__/loggingMiddleware.test.ts @@ -1,9 +1,9 @@ +import { json } from "body-parser"; import express from "express"; import supertest from "supertest"; import Transport from "winston-transport"; -import bodyParser from "body-parser"; -import loggingMiddleware from "../loggingMiddleware"; import logger from "../../../logging/logger"; +import loggingMiddleware from "../loggingMiddleware"; const logMock = jest.fn(); @@ -29,7 +29,7 @@ describe("loggingMiddleware", () => { const app = express(); const graphQLPath = "/"; - app.use(bodyParser.json()); + app.use(json()); app.use(loggingMiddleware("/")); app.get("/hello", (req, res) => { res.status(200).send("world"); diff --git a/back/src/common/middlewares/graphqlBodyParser.ts b/back/src/common/middlewares/graphqlBodyParser.ts index e76010c57ad..4c8bc77e2c6 100644 --- a/back/src/common/middlewares/graphqlBodyParser.ts +++ b/back/src/common/middlewares/graphqlBodyParser.ts @@ -1,5 +1,5 @@ import { Request, Response, NextFunction } from "express"; -import bodyParser from "body-parser"; +import { text } from "body-parser"; /** * GraphQL server middleware to support application/graphql requests @@ -7,7 +7,7 @@ import bodyParser from "body-parser"; */ export default (req: Request, res: Response, next: NextFunction) => { if (req.is("application/graphql")) { - bodyParser.text({ type: "application/graphql" })(req, res, () => { + text({ type: "application/graphql" })(req, res, () => { req.headers["content-type"] = "application/json"; req.body = { query: req.body diff --git a/back/src/companies/database.ts b/back/src/companies/database.ts index a51bf766726..b9021aa2938 100644 --- a/back/src/companies/database.ts +++ b/back/src/companies/database.ts @@ -4,10 +4,8 @@ import prisma from "src/prisma"; import { - CompanyWhereUniqueInput, User, - TraderReceiptWhereUniqueInput, - TransporterReceiptWhereUniqueInput, + Prisma, Company, TraderReceipt, TransporterReceipt @@ -25,11 +23,11 @@ import { CompanyMember } from "../generated/graphql/types"; export async function getCompanyOrCompanyNotFound({ id, siret -}: CompanyWhereUniqueInput) { +}: Prisma.CompanyWhereUniqueInput) { if (!id && !siret) { throw new Error("You should specify an id or a siret"); } - const company = await prisma.company.findOne({ + const company = await prisma.company.findUnique({ where: id ? { id } : { siret } }); if (company == null) { @@ -186,8 +184,8 @@ export async function getCompanyAdminUsers(siret: string) { export async function getTraderReceiptOrNotFound({ id -}: TraderReceiptWhereUniqueInput) { - const receipt = await prisma.traderReceipt.findOne({ where: { id } }); +}: Prisma.TraderReceiptWhereUniqueInput) { + const receipt = await prisma.traderReceipt.findUnique({ where: { id } }); if (receipt == null) { throw new TraderReceiptNotFound(); } @@ -196,8 +194,8 @@ export async function getTraderReceiptOrNotFound({ export async function getTransporterReceiptOrNotFound({ id -}: TransporterReceiptWhereUniqueInput) { - const receipt = await prisma.transporterReceipt.findOne({ where: { id } }); +}: Prisma.TransporterReceiptWhereUniqueInput) { + const receipt = await prisma.transporterReceipt.findUnique({ where: { id } }); if (receipt == null) { throw new TransporterReceiptNotFound(); } diff --git a/back/src/companies/resolvers/CompanyFavorite.ts b/back/src/companies/resolvers/CompanyFavorite.ts index c9e39ee19a2..952c00f5489 100644 --- a/back/src/companies/resolvers/CompanyFavorite.ts +++ b/back/src/companies/resolvers/CompanyFavorite.ts @@ -5,13 +5,13 @@ import { stringifyDates } from "../database"; const companyFavoriteResolvers: CompanyFavoriteResolvers = { transporterReceipt: async parent => { const transporterReceipt = await prisma.company - .findOne({ where: { siret: parent.siret } }) + .findUnique({ where: { siret: parent.siret } }) .transporterReceipt(); return stringifyDates(transporterReceipt); }, traderReceipt: async parent => { const traderReceipt = await prisma.company - .findOne({ where: { siret: parent.siret } }) + .findUnique({ where: { siret: parent.siret } }) .traderReceipt(); return stringifyDates(traderReceipt); } diff --git a/back/src/companies/resolvers/CompanyPrivate.ts b/back/src/companies/resolvers/CompanyPrivate.ts index 40e7a0555c5..fecfbc05947 100644 --- a/back/src/companies/resolvers/CompanyPrivate.ts +++ b/back/src/companies/resolvers/CompanyPrivate.ts @@ -12,13 +12,13 @@ const companyPrivateResolvers: CompanyPrivateResolvers = { }, transporterReceipt: async parent => { const transporterReceipt = await prisma.company - .findOne({ where: { siret: parent.siret } }) + .findUnique({ where: { siret: parent.siret } }) .transporterReceipt(); return stringifyDates(transporterReceipt); }, traderReceipt: async parent => { const traderReceipt = await prisma.company - .findOne({ where: { siret: parent.siret } }) + .findUnique({ where: { siret: parent.siret } }) .traderReceipt(); return stringifyDates(traderReceipt); } diff --git a/back/src/companies/resolvers/CompanyPublic.ts b/back/src/companies/resolvers/CompanyPublic.ts index 93f269e6649..f3f26390c71 100644 --- a/back/src/companies/resolvers/CompanyPublic.ts +++ b/back/src/companies/resolvers/CompanyPublic.ts @@ -5,13 +5,13 @@ import { stringifyDates } from "../database"; const companyPublicResolvers: CompanyPublicResolvers = { transporterReceipt: async parent => { const transporterReceipt = await prisma.company - .findOne({ where: { siret: parent.siret } }) + .findUnique({ where: { siret: parent.siret } }) .transporterReceipt(); return stringifyDates(transporterReceipt); }, traderReceipt: async parent => { const traderReceipt = await prisma.company - .findOne({ where: { siret: parent.siret } }) + .findUnique({ where: { siret: parent.siret } }) .traderReceipt(); return stringifyDates(traderReceipt); } diff --git a/back/src/companies/resolvers/CompanySearchResult.ts b/back/src/companies/resolvers/CompanySearchResult.ts index b882aa969e6..770b7a4dd27 100644 --- a/back/src/companies/resolvers/CompanySearchResult.ts +++ b/back/src/companies/resolvers/CompanySearchResult.ts @@ -5,13 +5,13 @@ import { stringifyDates } from "../database"; const companySearchResultResolvers: CompanySearchResultResolvers = { transporterReceipt: async parent => { const transporterReceipt = await prisma.company - .findOne({ where: { siret: parent.siret } }) + .findUnique({ where: { siret: parent.siret } }) .transporterReceipt(); return stringifyDates(transporterReceipt); }, traderReceipt: async parent => { const traderReceipt = await prisma.company - .findOne({ where: { siret: parent.siret } }) + .findUnique({ where: { siret: parent.siret } }) .traderReceipt(); return stringifyDates(traderReceipt); } diff --git a/back/src/companies/resolvers/mutations/__tests__/createCompany.integration.ts b/back/src/companies/resolvers/mutations/__tests__/createCompany.integration.ts index bfa3a939e75..cb99c7d22b9 100644 --- a/back/src/companies/resolvers/mutations/__tests__/createCompany.integration.ts +++ b/back/src/companies/resolvers/mutations/__tests__/createCompany.integration.ts @@ -162,7 +162,7 @@ describe("Mutation.createCompany", () => { } }); - const company = await prisma.company.findOne({ + const company = await prisma.company.findUnique({ where: { siret: companyInput.siret } }); expect(company.documentKeys).toEqual(["key1", "key2"]); diff --git a/back/src/companies/resolvers/mutations/__tests__/updateCompany.integration.ts b/back/src/companies/resolvers/mutations/__tests__/updateCompany.integration.ts index 7b709d1cc32..4af0d0e0b7c 100644 --- a/back/src/companies/resolvers/mutations/__tests__/updateCompany.integration.ts +++ b/back/src/companies/resolvers/mutations/__tests__/updateCompany.integration.ts @@ -55,7 +55,7 @@ describe("mutation updateCompany", () => { }); expect(data.updateCompany.id).toEqual(company.id); - const updatedCompany = await prisma.company.findOne({ + const updatedCompany = await prisma.company.findUnique({ where: { id: company.id } }); expect(updatedCompany).toMatchObject(variables); diff --git a/back/src/companies/resolvers/mutations/__tests__/updateTraderReceipt.integration.ts b/back/src/companies/resolvers/mutations/__tests__/updateTraderReceipt.integration.ts index 6eb7c6cb277..86be77dc797 100644 --- a/back/src/companies/resolvers/mutations/__tests__/updateTraderReceipt.integration.ts +++ b/back/src/companies/resolvers/mutations/__tests__/updateTraderReceipt.integration.ts @@ -46,7 +46,7 @@ describe("{ mutation { updateTraderReceipt } }", () => { expect(data.updateTraderReceipt).toEqual(update); // check record was modified in db - const { id, ...updated } = await prisma.traderReceipt.findOne({ + const { id, ...updated } = await prisma.traderReceipt.findUnique({ where: { id: createdReceipt.id } }); expect(updated.receiptNumber).toEqual(update.receiptNumber); diff --git a/back/src/companies/resolvers/mutations/__tests__/updateTransporterReceipt.integration.ts b/back/src/companies/resolvers/mutations/__tests__/updateTransporterReceipt.integration.ts index 445c69daffb..284f8eccd99 100644 --- a/back/src/companies/resolvers/mutations/__tests__/updateTransporterReceipt.integration.ts +++ b/back/src/companies/resolvers/mutations/__tests__/updateTransporterReceipt.integration.ts @@ -48,7 +48,7 @@ describe("{ mutation { updateTransporterReceipt } }", () => { expect(data.updateTransporterReceipt).toEqual(update); // check record was modified in db - const { id, ...updated } = await prisma.transporterReceipt.findOne({ + const { id, ...updated } = await prisma.transporterReceipt.findUnique({ where: { id: createdReceipt.id } }); expect(updated.receiptNumber).toEqual(update.receiptNumber); diff --git a/back/src/companies/resolvers/mutations/createCompany.ts b/back/src/companies/resolvers/mutations/createCompany.ts index ff720ab01a2..f3099543f47 100644 --- a/back/src/companies/resolvers/mutations/createCompany.ts +++ b/back/src/companies/resolvers/mutations/createCompany.ts @@ -1,4 +1,4 @@ -import { Company, CompanyCreateInput, User } from "@prisma/client"; +import { Company, Prisma, User } from "@prisma/client"; import { UserInputError } from "apollo-server-express"; import { convertUrls } from "src/companies/database"; import prisma from "src/prisma"; @@ -37,7 +37,7 @@ const createCompanyResolver: MutationResolvers["createCompany"] = async ( const siret = companyInput.siret.replace(/\s+/g, ""); const existingCompany = await prisma.company - .findOne({ + .findUnique({ where: { siret } @@ -55,7 +55,7 @@ const createCompanyResolver: MutationResolvers["createCompany"] = async ( } if (companyTypes.includes("ECO_ORGANISME")) { - const ecoOrganismeExists = await prisma.ecoOrganisme.findOne({ + const ecoOrganismeExists = await prisma.ecoOrganisme.findUnique({ where: { siret } }); if (!ecoOrganismeExists) { @@ -75,7 +75,7 @@ const createCompanyResolver: MutationResolvers["createCompany"] = async ( ); } - const companyCreateInput: CompanyCreateInput = { + const companyCreateInput: Prisma.CompanyCreateInput = { siret, codeNaf, gerepId, diff --git a/back/src/companies/resolvers/mutations/renewSecurityCode.ts b/back/src/companies/resolvers/mutations/renewSecurityCode.ts index 11ca40198f1..09a974ab4fa 100644 --- a/back/src/companies/resolvers/mutations/renewSecurityCode.ts +++ b/back/src/companies/resolvers/mutations/renewSecurityCode.ts @@ -31,7 +31,7 @@ export async function renewSecurityCodeFn( }); } - const company = await prisma.company.findOne({ where: { siret } }); + const company = await prisma.company.findUnique({ where: { siret } }); if (!company) { throw new UserInputError( diff --git a/back/src/companies/resolvers/queries/__tests__/favorites.integration.ts b/back/src/companies/resolvers/queries/__tests__/favorites.integration.ts index 61417f6f4c5..0e3ef746291 100644 --- a/back/src/companies/resolvers/queries/__tests__/favorites.integration.ts +++ b/back/src/companies/resolvers/queries/__tests__/favorites.integration.ts @@ -261,7 +261,7 @@ describe("query favorites", () => { } }); const temporaryStorageDetail = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .temporaryStorageDetail(); const { query } = makeClient({ ...user, auth: AuthType.Session }); diff --git a/back/src/companies/resolvers/queries/companyInfos.ts b/back/src/companies/resolvers/queries/companyInfos.ts index 51224d1134b..7ec900ab60f 100644 --- a/back/src/companies/resolvers/queries/companyInfos.ts +++ b/back/src/companies/resolvers/queries/companyInfos.ts @@ -29,7 +29,7 @@ export async function getCompanyInfos(siret: string): Promise { // retrieves trackdechets public CompanyInfo // it might be null if the company is not registered in TD - const trackdechetsCompanyInfo = await prisma.company.findOne({ + const trackdechetsCompanyInfo = await prisma.company.findUnique({ where: { siret }, select: { contactEmail: true, diff --git a/back/src/companies/resolvers/queries/favorites.ts b/back/src/companies/resolvers/queries/favorites.ts index 156d3e9f9d6..760d710ee01 100644 --- a/back/src/companies/resolvers/queries/favorites.ts +++ b/back/src/companies/resolvers/queries/favorites.ts @@ -4,12 +4,7 @@ import { FavoriteType, QueryResolvers } from "../../../generated/graphql/types"; -import { - Company, - CompanyType, - FormWhereInput, - SortOrder -} from "@prisma/client"; +import { Company, CompanyType, Prisma } from "@prisma/client"; import prisma from "src/prisma"; import { searchCompany } from "../../sirene"; import { applyAuthStrategies, AuthType } from "../../../auth"; @@ -65,10 +60,10 @@ async function getRecentPartners( type: FavoriteType ): Promise { const defaultArgs = { - orderBy: { updatedAt: "desc" as SortOrder }, + orderBy: { updatedAt: "desc" as Prisma.SortOrder }, take: 50 }; - const defaultWhere: FormWhereInput = { + const defaultWhere: Prisma.FormWhereInput = { OR: [ { owner: { id: userID } }, { emitterCompanySiret: siret }, diff --git a/back/src/events/forms.ts b/back/src/events/forms.ts index fd44b940c53..91e225aa44e 100644 --- a/back/src/events/forms.ts +++ b/back/src/events/forms.ts @@ -126,7 +126,7 @@ export async function mailWhenFormIsDeclined(payload: TDEventPayload
) { ) { return; } - const form = await prisma.form.findOne({ where: { id: payload.node.id } }); + const form = await prisma.form.findUnique({ where: { id: payload.node.id } }); // build pdf as a base64 string const { NOTIFY_DREAL_WHEN_FORM_DECLINED } = process.env; @@ -234,7 +234,7 @@ async function mailWhenFormTraceabilityIsBroken(payload: TDEventPayload) { return; } - const form = await prisma.form.findOne({ where: { id: payload.node.id } }); + const form = await prisma.form.findUnique({ where: { id: payload.node.id } }); return sendMail( userMails.formTraceabilityBreak( form.emitterCompanyMail, diff --git a/back/src/forms/__tests__/permissions.integration.ts b/back/src/forms/__tests__/permissions.integration.ts index bc6825c5024..5d2883052ed 100644 --- a/back/src/forms/__tests__/permissions.integration.ts +++ b/back/src/forms/__tests__/permissions.integration.ts @@ -107,7 +107,7 @@ async function checkTransporterAfterTempStoragePermission( ownerId: owner.id }); const tempStorageDetail = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .temporaryStorageDetail(); await prisma.temporaryStorageDetail.update({ data: { transporterCompanySiret: company.siret }, @@ -125,7 +125,7 @@ async function checkDestinationAfterTempStoragePermission( ownerId: owner.id }); const tempStorageDetail = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .temporaryStorageDetail(); await prisma.temporaryStorageDetail.update({ data: { destinationCompanySiret: company.siret }, diff --git a/back/src/forms/database.ts b/back/src/forms/database.ts index 3ff7146a9dc..4f427dd4f1a 100644 --- a/back/src/forms/database.ts +++ b/back/src/forms/database.ts @@ -2,7 +2,7 @@ * PRISMA HELPER FUNCTIONS */ -import { Form, FormWhereInput, FormWhereUniqueInput } from "@prisma/client"; +import { Form, Prisma } from "@prisma/client"; import { UserInputError } from "apollo-server-express"; import prisma from "src/prisma"; import { FormRole } from "../generated/graphql/types"; @@ -15,12 +15,14 @@ import { FullForm } from "./types"; * @param form */ export async function getFullForm(form: Form): Promise { - const owner = await prisma.form.findOne({ where: { id: form.id } }).owner(); + const owner = await prisma.form + .findUnique({ where: { id: form.id } }) + .owner(); const temporaryStorage = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .temporaryStorageDetail(); const transportSegments = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .transportSegments(); return { ...form, @@ -36,11 +38,11 @@ export async function getFullForm(form: Form): Promise { export async function getFormOrFormNotFound({ id, readableId -}: FormWhereUniqueInput) { +}: Prisma.FormWhereUniqueInput) { if (!id && !readableId) { throw new UserInputError("You should specify an id or a readableId"); } - const form = await prisma.form.findOne({ + const form = await prisma.form.findUnique({ where: id ? { id } : { readableId } }); if (form == null || form.isDeleted == true) { @@ -58,7 +60,9 @@ export async function getFormOrFormNotFound({ * @param roles optional [FormRole] to refine filter */ export function getFormsRightFilter(siret: string, roles?: FormRole[]) { - const filtersByRole: { [key in FormRole]: Partial[] } = { + const filtersByRole: { + [key in FormRole]: Partial[]; + } = { ["RECIPIENT"]: [ { recipientCompanySiret: siret }, { diff --git a/back/src/forms/exports/streams.ts b/back/src/forms/exports/streams.ts index 3f05b9a6aff..41dccd7143d 100644 --- a/back/src/forms/exports/streams.ts +++ b/back/src/forms/exports/streams.ts @@ -1,5 +1,5 @@ import { Readable, Transform, ReadableOptions } from "stream"; -import { Form, FormWhereInput } from "@prisma/client"; +import { Form, Prisma } from "@prisma/client"; import prisma from "src/prisma"; import { flattenForm } from "./transformers"; import { formatRow } from "./columns"; @@ -17,7 +17,7 @@ class FormReader extends Readable { } interface FormReaderArgs { - whereInput?: FormWhereInput; + whereInput?: Prisma.FormWhereInput; fieldsSelection?: Record; chunk?: number; } diff --git a/back/src/forms/exports/where-inputs.ts b/back/src/forms/exports/where-inputs.ts index a6e51273975..e6d5c42dbac 100644 --- a/back/src/forms/exports/where-inputs.ts +++ b/back/src/forms/exports/where-inputs.ts @@ -1,4 +1,4 @@ -import { FormWhereInput } from "@prisma/client"; +import { Prisma } from "@prisma/client"; import { FormsRegisterExportType } from "../../generated/graphql/types"; /** @@ -11,9 +11,9 @@ export function formsWhereInput( startDate?: Date, endDate?: Date, wasteCode?: string -): FormWhereInput { +): Prisma.FormWhereInput { // build prisma where input - const whereInputs: FormWhereInput[] = []; + const whereInputs: Prisma.FormWhereInput[] = []; if (startDate) { whereInputs.push({ sentAt: { gte: startDate } }); @@ -43,7 +43,7 @@ export function formsWhereInput( /** * Forms corresponding to outgoing wastes of a list of production companies */ -function outgoingWasteWhereInput(sirets: string[]): FormWhereInput { +function outgoingWasteWhereInput(sirets: string[]): Prisma.FormWhereInput { return { OR: [ { emitterCompanySiret: { in: sirets } }, @@ -57,7 +57,7 @@ function outgoingWasteWhereInput(sirets: string[]): FormWhereInput { * Forms corresponding to incoming wastes of a list of treatment or TTR companies * We need to handle cases whith a temp storage */ -function incomingWasteWhereInput(sirets: string[]): FormWhereInput { +function incomingWasteWhereInput(sirets: string[]): Prisma.FormWhereInput { return { OR: [ { @@ -110,7 +110,7 @@ function incomingWasteWhereInput(sirets: string[]): FormWhereInput { * Forms corresponding to transported wastes of a list of transporter companies * We need to handle cases of multiple transporters with temporary storage */ -function transportedWasteWhereInput(sirets: string[]): FormWhereInput { +function transportedWasteWhereInput(sirets: string[]): Prisma.FormWhereInput { return { OR: [ { @@ -152,7 +152,7 @@ function transportedWasteWhereInput(sirets: string[]): FormWhereInput { /** * Forms corresponding to traded waste of a list of trader companies */ -function tradedWasteWhereInput(sirets: string[]): FormWhereInput { +function tradedWasteWhereInput(sirets: string[]): Prisma.FormWhereInput { return { AND: [ { @@ -167,7 +167,7 @@ function tradedWasteWhereInput(sirets: string[]): FormWhereInput { * Forms where a list of companies are present for any status * excepted DRAFT and SEALED */ -function allWasteWhereInput(sirets: string[]): FormWhereInput { +function allWasteWhereInput(sirets: string[]): Prisma.FormWhereInput { return { AND: [ { diff --git a/back/src/forms/form-converter.ts b/back/src/forms/form-converter.ts index 663ccd856c5..b7a96726f4e 100644 --- a/back/src/forms/form-converter.ts +++ b/back/src/forms/form-converter.ts @@ -2,9 +2,7 @@ import { Form as PrismaForm, TemporaryStorageDetail as PrismaTemporaryStorageDetail, TransportSegment as PrismaTransportSegment, - FormCreateInput, - TemporaryStorageDetailCreateInput, - TemporaryStorageDetailUpdateInput + Prisma } from "@prisma/client"; import { Form as GraphQLForm, @@ -130,7 +128,7 @@ export function chain(o: T, getter: (o: T) => K): K | null | undefined { function flattenDestinationInput(input: { destination?: DestinationInput; -}): TemporaryStorageDetailCreateInput { +}): Prisma.TemporaryStorageDetailCreateInput { return { destinationCompanyName: chain(input.destination, d => chain(d.company, c => c.name) @@ -347,7 +345,7 @@ export function flattenFormInput( | "trader" | "ecoOrganisme" > -): Partial { +): Partial { return safeInput({ customId: formInput.customId, ...flattenEmitterInput(formInput), @@ -361,7 +359,7 @@ export function flattenFormInput( export function flattenProcessedFormInput( processedFormInput: ProcessedFormInput -): Partial { +): Partial { const { nextDestination, ...rest } = processedFormInput; return safeInput({ ...rest, @@ -371,7 +369,7 @@ export function flattenProcessedFormInput( export function flattenImportPaperFormInput( input: ImportPaperFormInput -): Partial { +): Partial { const { id, customId, @@ -415,13 +413,13 @@ function flattenReceivedInfo(receivedInfo: ReceivedFormInput) { export function flattenTemporaryStorageDetailInput( tempStorageInput: TemporaryStorageDetailInput -): TemporaryStorageDetailCreateInput { +): Prisma.TemporaryStorageDetailCreateInput { return safeInput(flattenDestinationInput(tempStorageInput)); } export function flattenResealedFormInput( resealedFormInput: ResealedFormInput -): TemporaryStorageDetailUpdateInput { +): Prisma.TemporaryStorageDetailUpdateInput { return safeInput({ ...flattenDestinationInput(resealedFormInput), ...flattenWasteDetailsInput(resealedFormInput), @@ -431,7 +429,7 @@ export function flattenResealedFormInput( export function flattenResentFormInput( resentFormInput: ResentFormInput -): TemporaryStorageDetailUpdateInput { +): Prisma.TemporaryStorageDetailUpdateInput { return safeInput({ ...flattenDestinationInput(resentFormInput), ...flattenWasteDetailsInput(resentFormInput), diff --git a/back/src/forms/pdf/downloadPdf.ts b/back/src/forms/pdf/downloadPdf.ts index b675dbca2c3..46f3eef58b6 100644 --- a/back/src/forms/pdf/downloadPdf.ts +++ b/back/src/forms/pdf/downloadPdf.ts @@ -10,7 +10,7 @@ export default async function downloadPdf(res: Response, { id }) { res.status(500).send("Identifiant du bordereau manquant."); } - const form = await prisma.form.findOne({ where: { id } }); + const form = await prisma.form.findUnique({ where: { id } }); const date = new Date(); const fileName = `BSD_${form.readableId}_${date.getDate()}-${ diff --git a/back/src/forms/pdf/generator.ts b/back/src/forms/pdf/generator.ts index 0e6801bbbbf..afa325c7204 100644 --- a/back/src/forms/pdf/generator.ts +++ b/back/src/forms/pdf/generator.ts @@ -31,13 +31,13 @@ const multimodalYOffset = 85; */ export const buildPdf = async (form: Form) => { const appendix2Forms = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .appendix2Forms(); const segments = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .transportSegments(); const temporaryStorageDetail = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .temporaryStorageDetail(); const params = { ...form, appendix2Forms, temporaryStorageDetail }; diff --git a/back/src/forms/resolvers/forms/appendix2Forms.ts b/back/src/forms/resolvers/forms/appendix2Forms.ts index 47889c04759..a454df58162 100644 --- a/back/src/forms/resolvers/forms/appendix2Forms.ts +++ b/back/src/forms/resolvers/forms/appendix2Forms.ts @@ -4,7 +4,7 @@ import { stringifyDates } from "src/forms/database"; const appendix2FormsResolver: FormResolvers["appendix2Forms"] = async form => { const appendix2Forms = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .appendix2Forms(); return appendix2Forms.map(form => stringifyDates(form)); }; diff --git a/back/src/forms/resolvers/forms/stateSummary.ts b/back/src/forms/resolvers/forms/stateSummary.ts index d6b14e87330..2febdf89801 100644 --- a/back/src/forms/resolvers/forms/stateSummary.ts +++ b/back/src/forms/resolvers/forms/stateSummary.ts @@ -117,7 +117,7 @@ function getQuantity( export async function getStateSummary(form: Form) { const temporaryStorageDetail = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .temporaryStorageDetail(); const packagingInfos = diff --git a/back/src/forms/resolvers/forms/temporaryStorageDetail.ts b/back/src/forms/resolvers/forms/temporaryStorageDetail.ts index 620903439b5..1e647192178 100644 --- a/back/src/forms/resolvers/forms/temporaryStorageDetail.ts +++ b/back/src/forms/resolvers/forms/temporaryStorageDetail.ts @@ -4,7 +4,7 @@ import { expandTemporaryStorageFromDb } from "../../form-converter"; const temporaryStorageDetailsResolver: FormResolvers["temporaryStorageDetail"] = async form => { const temporaryStorageDetail = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .temporaryStorageDetail(); return temporaryStorageDetail diff --git a/back/src/forms/resolvers/forms/transportSegments.ts b/back/src/forms/resolvers/forms/transportSegments.ts index 9d5b02d3b70..232d0d427a1 100644 --- a/back/src/forms/resolvers/forms/transportSegments.ts +++ b/back/src/forms/resolvers/forms/transportSegments.ts @@ -4,7 +4,7 @@ import { expandTransportSegmentFromDb } from "../../form-converter"; const transportSegmentResolver: FormResolvers["transportSegments"] = async form => { const segments = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .transportSegments({ orderBy: { segmentNumber: "asc" } }); return segments.map(el => ({ // TODO-PRISMA diff --git a/back/src/forms/resolvers/mutations/__mocks__/data.ts b/back/src/forms/resolvers/mutations/__mocks__/data.ts index 62a2ccb4c01..0d7bac4eed5 100644 --- a/back/src/forms/resolvers/mutations/__mocks__/data.ts +++ b/back/src/forms/resolvers/mutations/__mocks__/data.ts @@ -1,14 +1,19 @@ import { GraphQLContext } from "../../../../types"; -import { EmitterType, QuantityType, Form as PrismaForm } from "@prisma/client"; +import { + EmitterType, + QuantityType, + Form as PrismaForm, + User +} from "@prisma/client"; import { Form as GraphQLForm } from "../../../../generated/graphql/types"; -export function getNewValidPrismaForm(): PrismaForm { +export function getNewValidPrismaForm(): Partial { return { id: "cjplbvecc000d0766j32r19am", readableId: "TD-xxx", isImportedFromPaper: false, - createdAt: "2018-12-11T00:00:00.000Z", - updatedAt: "2018-12-11T00:00:00.000Z", + createdAt: new Date("2018-12-11T00:00:00.000Z"), + updatedAt: new Date("2018-12-11T00:00:00.000Z"), status: "DRAFT", emitterType: "PRODUCER", emitterWorkSiteName: "", @@ -33,7 +38,7 @@ export function getNewValidPrismaForm(): PrismaForm { recipientIsTempStorage: false, transporterReceipt: "sdfg", transporterDepartment: "82", - transporterValidityLimit: "2018-12-11T00:00:00.000Z", + transporterValidityLimit: new Date("2018-12-11T00:00:00.000Z"), transporterNumberPlate: "12345", transporterCompanyName: "A company 4", transporterCompanySiret: "25698741547863", @@ -220,9 +225,9 @@ export function getContext(): GraphQLContext { name: "username", email: "user@trackdechets.fr", password: "pass", - createdAt: "", - updatedAt: "" - }, + createdAt: new Date(), + updatedAt: new Date() + } as User, req: null as any, res: null as any }; diff --git a/back/src/forms/resolvers/mutations/__tests__/deleteForm.integration.ts b/back/src/forms/resolvers/mutations/__tests__/deleteForm.integration.ts index 5ebe91ee007..4d39c8b91ec 100644 --- a/back/src/forms/resolvers/mutations/__tests__/deleteForm.integration.ts +++ b/back/src/forms/resolvers/mutations/__tests__/deleteForm.integration.ts @@ -39,7 +39,7 @@ describe("Mutation.deleteForm", () => { }) }) ]); - const intactForm = await prisma.form.findOne({ where: { id: form.id } }); + const intactForm = await prisma.form.findUnique({ where: { id: form.id } }); expect(intactForm.isDeleted).toBe(false); }); @@ -64,7 +64,7 @@ describe("Mutation.deleteForm", () => { }) }) ]); - const intactForm = await prisma.form.findOne({ where: { id: form.id } }); + const intactForm = await prisma.form.findUnique({ where: { id: form.id } }); expect(intactForm.isDeleted).toBe(false); }); @@ -88,7 +88,7 @@ describe("Mutation.deleteForm", () => { }) ]); - const intactForm = await prisma.form.findOne({ where: { id: form.id } }); + const intactForm = await prisma.form.findUnique({ where: { id: form.id } }); expect(intactForm.isDeleted).toBe(false); }); @@ -109,7 +109,9 @@ describe("Mutation.deleteForm", () => { expect(data.deleteForm.id).toBeTruthy(); - const deletedForm = await prisma.form.findOne({ where: { id: form.id } }); + const deletedForm = await prisma.form.findUnique({ + where: { id: form.id } + }); expect(deletedForm.isDeleted).toBe(true); } ); diff --git a/back/src/forms/resolvers/mutations/__tests__/duplicateForm.integration.ts b/back/src/forms/resolvers/mutations/__tests__/duplicateForm.integration.ts index ba3d08f2152..1791a08c7ee 100644 --- a/back/src/forms/resolvers/mutations/__tests__/duplicateForm.integration.ts +++ b/back/src/forms/resolvers/mutations/__tests__/duplicateForm.integration.ts @@ -111,7 +111,7 @@ describe("Mutation.duplicateForm", () => { id } }); - const duplicatedForm = await prisma.form.findOne({ + const duplicatedForm = await prisma.form.findUnique({ where: { id: data.duplicateForm.id } }); @@ -234,7 +234,7 @@ describe("Mutation.duplicateForm", () => { transporterDepartment, transporterValidityLimit } = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .temporaryStorageDetail(); const { mutate } = makeClient(user); @@ -243,11 +243,11 @@ describe("Mutation.duplicateForm", () => { id: form.id } }); - const duplicatedForm = await prisma.form.findOne({ + const duplicatedForm = await prisma.form.findUnique({ where: { id: data.duplicateForm.id } }); const duplicatedTemporaryStorageDetail = await prisma.form - .findOne({ + .findUnique({ where: { id: duplicatedForm.id } diff --git a/back/src/forms/resolvers/mutations/__tests__/importPaperForm.integration.ts b/back/src/forms/resolvers/mutations/__tests__/importPaperForm.integration.ts index 5684f66bf3c..8a4064c87dd 100644 --- a/back/src/forms/resolvers/mutations/__tests__/importPaperForm.integration.ts +++ b/back/src/forms/resolvers/mutations/__tests__/importPaperForm.integration.ts @@ -1,4 +1,4 @@ -import { Form, FormCreateInput } from "@prisma/client"; +import { Form, Prisma } from "@prisma/client"; import { resetDatabase } from "integration-tests/helper"; import prisma from "src/prisma"; import { ImportPaperFormInput } from "../../../../generated/graphql/types"; @@ -174,7 +174,7 @@ describe("mutation / importPaperForm", () => { expect(data.importPaperForm.status).toEqual("PROCESSED"); - const updatedForm = await prisma.form.findOne({ + const updatedForm = await prisma.form.findUnique({ where: { id: data.importPaperForm.id } }); @@ -267,7 +267,7 @@ describe("mutation / importPaperForm", () => { const { user, company } = await userWithCompanyFactory("MEMBER"); - const formCreateInput: FormCreateInput = { + const formCreateInput: Prisma.FormCreateInput = { ...baseData, readableId: getReadableId(), owner: { @@ -290,7 +290,9 @@ describe("mutation / importPaperForm", () => { } } }); - const updatedForm = await prisma.form.findOne({ where: { id: form.id } }); + const updatedForm = await prisma.form.findUnique({ + where: { id: form.id } + }); expect(updatedForm.status).toEqual("PROCESSED"); expect(updatedForm.isImportedFromPaper).toEqual(true); @@ -352,7 +354,7 @@ describe("mutation / importPaperForm", () => { const { user, company } = await userWithCompanyFactory("MEMBER"); - const formCreateInput: FormCreateInput = { + const formCreateInput: Prisma.FormCreateInput = { ...baseData, readableId: getReadableId(), owner: { @@ -382,7 +384,9 @@ describe("mutation / importPaperForm", () => { } } }); - const updatedForm = await prisma.form.findOne({ where: { id: form.id } }); + const updatedForm = await prisma.form.findUnique({ + where: { id: form.id } + }); expect(updatedForm.status).toEqual("PROCESSED"); expect(updatedForm.emitterCompanyName).toEqual(emitterCompanyName); }); @@ -392,7 +396,7 @@ describe("mutation / importPaperForm", () => { const { user, company } = await userWithCompanyFactory("MEMBER"); - const formCreateInput: FormCreateInput = { + const formCreateInput: Prisma.FormCreateInput = { ...baseData, readableId: getReadableId(), owner: { @@ -426,7 +430,7 @@ describe("mutation / importPaperForm", () => { const user = await userFactory(); - const formCreateInput: FormCreateInput = { + const formCreateInput: Prisma.FormCreateInput = { ...baseData, readableId: getReadableId(), owner: { @@ -459,7 +463,7 @@ describe("mutation / importPaperForm", () => { const { user, company } = await userWithCompanyFactory("MEMBER"); - const formCreateInput: FormCreateInput = { + const formCreateInput: Prisma.FormCreateInput = { ...baseData, readableId: getReadableId(), owner: { @@ -498,7 +502,7 @@ describe("mutation / importPaperForm", () => { const { user, company } = await userWithCompanyFactory("MEMBER"); - const formCreateInput: FormCreateInput = { + const formCreateInput: Prisma.FormCreateInput = { ...baseData, readableId: getReadableId(), owner: { diff --git a/back/src/forms/resolvers/mutations/__tests__/markAsProcessed.integration.ts b/back/src/forms/resolvers/mutations/__tests__/markAsProcessed.integration.ts index 0d9d6ae98cf..21f233a2be4 100644 --- a/back/src/forms/resolvers/mutations/__tests__/markAsProcessed.integration.ts +++ b/back/src/forms/resolvers/mutations/__tests__/markAsProcessed.integration.ts @@ -78,7 +78,9 @@ describe("mutation.markAsProcessed", () => { } }); - const resultingForm = await prisma.form.findOne({ where: { id: form.id } }); + const resultingForm = await prisma.form.findUnique({ + where: { id: form.id } + }); expect(resultingForm.status).toBe("PROCESSED"); // check relevant statusLog is created @@ -154,7 +156,9 @@ describe("mutation.markAsProcessed", () => { expect(errors[0].message).toBe( "Cette opération d’élimination / valorisation n'existe pas." ); - const resultingForm = await prisma.form.findOne({ where: { id: form.id } }); + const resultingForm = await prisma.form.findUnique({ + where: { id: form.id } + }); expect(resultingForm.status).toBe("RECEIVED"); // no statusLog is created @@ -202,7 +206,9 @@ describe("mutation.markAsProcessed", () => { } }); - const resultingForm = await prisma.form.findOne({ where: { id: form.id } }); + const resultingForm = await prisma.form.findUnique({ + where: { id: form.id } + }); expect(resultingForm.status).toBe("AWAITING_GROUP"); }); @@ -274,7 +280,9 @@ describe("mutation.markAsProcessed", () => { } }); - const resultingForm = await prisma.form.findOne({ where: { id: form.id } }); + const resultingForm = await prisma.form.findUnique({ + where: { id: form.id } + }); expect(resultingForm.status).toBe("NO_TRACEABILITY"); }); @@ -313,7 +321,9 @@ describe("mutation.markAsProcessed", () => { } }); - const resultingForm = await prisma.form.findOne({ where: { id: form.id } }); + const resultingForm = await prisma.form.findUnique({ + where: { id: form.id } + }); expect(resultingForm).toMatchObject({ status: "AWAITING_GROUP", nextDestinationCompanyCountry: "FR" @@ -356,7 +366,9 @@ describe("mutation.markAsProcessed", () => { } }); - const resultingForm = await prisma.form.findOne({ where: { id: form.id } }); + const resultingForm = await prisma.form.findUnique({ + where: { id: form.id } + }); expect(resultingForm.status).toBe("AWAITING_GROUP"); expect(resultingForm.nextDestinationCompanyCountry).toBe("DE"); }); @@ -440,7 +452,7 @@ describe("mutation.markAsProcessed", () => { } }); - const appendix2grouped = await prisma.form.findOne({ + const appendix2grouped = await prisma.form.findUnique({ where: { id: appendix2.id } }); expect(appendix2grouped.status).toEqual("PROCESSED"); diff --git a/back/src/forms/resolvers/mutations/__tests__/markAsReceived.integration.ts b/back/src/forms/resolvers/mutations/__tests__/markAsReceived.integration.ts index bab0594cd1d..ce860fb3ae2 100644 --- a/back/src/forms/resolvers/mutations/__tests__/markAsReceived.integration.ts +++ b/back/src/forms/resolvers/mutations/__tests__/markAsReceived.integration.ts @@ -60,7 +60,7 @@ describe("Test Form reception", () => { } }); - const frm = await prisma.form.findOne({ where: { id: form.id } }); + const frm = await prisma.form.findUnique({ where: { id: form.id } }); expect(frm.status).toBe("RECEIVED"); expect(frm.wasteAcceptationStatus).toBe("ACCEPTED"); @@ -105,7 +105,7 @@ describe("Test Form reception", () => { } }); - const frm = await prisma.form.findOne({ where: { id: form.id } }); + const frm = await prisma.form.findUnique({ where: { id: form.id } }); // form was not accepted, still sent expect(frm.status).toBe("SENT"); expect(frm.wasteAcceptationStatus).toBe(null); @@ -140,7 +140,7 @@ describe("Test Form reception", () => { } }); - const frm = await prisma.form.findOne({ where: { id: form.id } }); + const frm = await prisma.form.findUnique({ where: { id: form.id } }); // form was not accepted, still sent expect(frm.status).toBe("SENT"); expect(frm.wasteAcceptationStatus).toBe(null); @@ -175,7 +175,7 @@ describe("Test Form reception", () => { } }); - const frm = await prisma.form.findOne({ where: { id: form.id } }); + const frm = await prisma.form.findUnique({ where: { id: form.id } }); // form was refused expect(frm.status).toBe("REFUSED"); @@ -219,7 +219,7 @@ describe("Test Form reception", () => { } }); - const frm = await prisma.form.findOne({ where: { id: form.id } }); + const frm = await prisma.form.findUnique({ where: { id: form.id } }); // form is still sent expect(frm.status).toBe("SENT"); @@ -261,7 +261,7 @@ describe("Test Form reception", () => { } }); - const frm = await prisma.form.findOne({ where: { id: form.id } }); + const frm = await prisma.form.findUnique({ where: { id: form.id } }); // form was not accepted expect(frm.status).toBe("RECEIVED"); expect(frm.wasteAcceptationStatus).toBe("PARTIALLY_REFUSED"); @@ -316,7 +316,7 @@ describe("Test Form reception", () => { } }); - const frm = await prisma.form.findOne({ + const frm = await prisma.form.findUnique({ where: { id: alreadyReceivedForm.id } }); // form is not updated by the last mutation @@ -358,7 +358,7 @@ describe("Test Form reception", () => { } }); - const frm = await prisma.form.findOne({ where: { id: form.id } }); + const frm = await prisma.form.findUnique({ where: { id: form.id } }); expect(frm.status).toBe("SENT"); expect(frm.wasteAcceptationStatus).toBe(null); @@ -408,7 +408,7 @@ describe("Test Form reception", () => { } }); - const frm = await prisma.form.findOne({ where: { id: form.id } }); + const frm = await prisma.form.findUnique({ where: { id: form.id } }); expect(frm.status).toBe("RECEIVED"); expect(frm.wasteAcceptationStatus).toBe("ACCEPTED"); @@ -473,7 +473,7 @@ describe("Test Form reception", () => { } }); - const frm = await prisma.form.findOne({ where: { id: form.id } }); + const frm = await prisma.form.findUnique({ where: { id: form.id } }); expect(frm.status).toBe("SENT"); diff --git a/back/src/forms/resolvers/mutations/__tests__/markAsResealed.integration.ts b/back/src/forms/resolvers/mutations/__tests__/markAsResealed.integration.ts index 35660e5f10d..b23ef76c7d6 100644 --- a/back/src/forms/resolvers/mutations/__tests__/markAsResealed.integration.ts +++ b/back/src/forms/resolvers/mutations/__tests__/markAsResealed.integration.ts @@ -41,7 +41,9 @@ describe("Mutation markAsResealed", () => { } }); - const resealedForm = await prisma.form.findOne({ where: { id: form.id } }); + const resealedForm = await prisma.form.findUnique({ + where: { id: form.id } + }); expect(resealedForm.status).toEqual("RESEALED"); }); @@ -79,7 +81,9 @@ describe("Mutation markAsResealed", () => { "Destination prévue: Le siret de l'entreprise est obligatoire" ); expect(errors[0].extensions.code).toEqual(ErrorCode.BAD_USER_INPUT); - const resealedForm = await prisma.form.findOne({ where: { id: form.id } }); + const resealedForm = await prisma.form.findUnique({ + where: { id: form.id } + }); expect(resealedForm.status).toEqual("TEMP_STORED"); }); @@ -119,7 +123,9 @@ describe("Mutation markAsResealed", () => { } }); - const resealedForm = await prisma.form.findOne({ where: { id: form.id } }); + const resealedForm = await prisma.form.findUnique({ + where: { id: form.id } + }); expect(resealedForm.status).toEqual("RESEALED"); }); }); diff --git a/back/src/forms/resolvers/mutations/__tests__/markAsResent.integration.ts b/back/src/forms/resolvers/mutations/__tests__/markAsResent.integration.ts index c0fde23d166..90641f7eea6 100644 --- a/back/src/forms/resolvers/mutations/__tests__/markAsResent.integration.ts +++ b/back/src/forms/resolvers/mutations/__tests__/markAsResent.integration.ts @@ -74,7 +74,9 @@ describe("Mutation markAsResent", () => { } }); - const resealedForm = await prisma.form.findOne({ where: { id: form.id } }); + const resealedForm = await prisma.form.findUnique({ + where: { id: form.id } + }); expect(resealedForm.status).toEqual("RESENT"); }); @@ -115,7 +117,9 @@ describe("Mutation markAsResent", () => { "Destination prévue: Le siret de l'entreprise est obligatoire" ); expect(errors[0].extensions.code).toEqual(ErrorCode.BAD_USER_INPUT); - const resealedForm = await prisma.form.findOne({ where: { id: form.id } }); + const resealedForm = await prisma.form.findUnique({ + where: { id: form.id } + }); expect(resealedForm.status).toEqual("TEMP_STORED"); }); @@ -157,7 +161,9 @@ describe("Mutation markAsResent", () => { } }); - const resealedForm = await prisma.form.findOne({ where: { id: form.id } }); + const resealedForm = await prisma.form.findUnique({ + where: { id: form.id } + }); expect(resealedForm.status).toEqual("RESENT"); }); }); diff --git a/back/src/forms/resolvers/mutations/__tests__/markAsSealed.integration.ts b/back/src/forms/resolvers/mutations/__tests__/markAsSealed.integration.ts index d57ab28f984..7b48edbce51 100644 --- a/back/src/forms/resolvers/mutations/__tests__/markAsSealed.integration.ts +++ b/back/src/forms/resolvers/mutations/__tests__/markAsSealed.integration.ts @@ -70,7 +70,7 @@ describe("Mutation.markAsSealed", () => { } }); - form = await prisma.form.findOne({ where: { id: form.id } }); + form = await prisma.form.findUnique({ where: { id: form.id } }); expect(form.status).toEqual("SEALED"); @@ -123,7 +123,7 @@ describe("Mutation.markAsSealed", () => { } }); - form = await prisma.form.findOne({ where: { id: form.id } }); + form = await prisma.form.findUnique({ where: { id: form.id } }); expect(form.status).toEqual("SEALED"); }); @@ -192,7 +192,9 @@ describe("Mutation.markAsSealed", () => { }); expect(errors[0].extensions.code).toBe("FORBIDDEN"); - const resultingForm = await prisma.form.findOne({ where: { id: form.id } }); + const resultingForm = await prisma.form.findUnique({ + where: { id: form.id } + }); expect(resultingForm.status).toEqual("DRAFT"); }); @@ -226,7 +228,7 @@ describe("Mutation.markAsSealed", () => { "Émetteur: Le contact dans l'entreprise est obligatoire"; expect(errors[0].message).toBe(errMessage); - form = await prisma.form.findOne({ where: { id: form.id } }); + form = await prisma.form.findUnique({ where: { id: form.id } }); expect(form.status).toEqual("DRAFT"); // no statusLog is created @@ -267,7 +269,7 @@ describe("Mutation.markAsSealed", () => { "Le code déchet n'est pas reconnu comme faisant partie de la liste officielle du code de l'environnement." ) ); - form = await prisma.form.findOne({ where: { id: form.id } }); + form = await prisma.form.findUnique({ where: { id: form.id } }); expect(form.status).toEqual("DRAFT"); @@ -363,7 +365,7 @@ describe("Mutation.markAsSealed", () => { variables: { id: form.id } }); - const appendix2grouped = await prisma.form.findOne({ + const appendix2grouped = await prisma.form.findUnique({ where: { id: appendix2.id } }); expect(appendix2grouped.status).toEqual("GROUPED"); diff --git a/back/src/forms/resolvers/mutations/__tests__/markAsSent.integration.ts b/back/src/forms/resolvers/mutations/__tests__/markAsSent.integration.ts index 0b557e28fc7..35cf423520a 100644 --- a/back/src/forms/resolvers/mutations/__tests__/markAsSent.integration.ts +++ b/back/src/forms/resolvers/mutations/__tests__/markAsSent.integration.ts @@ -75,7 +75,7 @@ describe("{ mutation { markAsSent } }", () => { } }); - form = await prisma.form.findOne({ where: { id: form.id } }); + form = await prisma.form.findUnique({ where: { id: form.id } }); expect(form.status).toEqual("SENT"); @@ -117,7 +117,7 @@ describe("{ mutation { markAsSent } }", () => { await mutate(mutation); - form = await prisma.form.findOne({ where: { id: form.id } }); + form = await prisma.form.findUnique({ where: { id: form.id } }); expect(form.status).toEqual("SENT"); @@ -153,7 +153,7 @@ describe("{ mutation { markAsSent } }", () => { } }); - form = await prisma.form.findOne({ where: { id: form.id } }); + form = await prisma.form.findUnique({ where: { id: form.id } }); expect(form.status).toEqual("SENT"); @@ -192,7 +192,7 @@ describe("{ mutation { markAsSent } }", () => { } }); - form = await prisma.form.findOne({ where: { id: form.id } }); + form = await prisma.form.findUnique({ where: { id: form.id } }); expect(form.status).toEqual("SENT"); @@ -230,7 +230,9 @@ describe("{ mutation { markAsSent } }", () => { }); expect(errors[0].extensions.code).toBe("FORBIDDEN"); - const resultingForm = await prisma.form.findOne({ where: { id: form.id } }); + const resultingForm = await prisma.form.findUnique({ + where: { id: form.id } + }); expect(resultingForm.status).toEqual("SEALED"); expect(resultingForm.currentTransporterSiret).toBeNull(); @@ -269,7 +271,7 @@ describe("{ mutation { markAsSent } }", () => { "Le code déchet n'est pas reconnu comme faisant partie de la liste officielle du code de l'environnement." ) ); - form = await prisma.form.findOne({ where: { id: form.id } }); + form = await prisma.form.findUnique({ where: { id: form.id } }); expect(form.status).toEqual("DRAFT"); @@ -314,7 +316,7 @@ describe("{ mutation { markAsSent } }", () => { expect(errors[0].message).toEqual( "La date d'envoi n'est pas formatée correctement" ); - form = await prisma.form.findOne({ where: { id: form.id } }); + form = await prisma.form.findUnique({ where: { id: form.id } }); expect(form.status).toEqual("SEALED"); @@ -364,7 +366,7 @@ describe("{ mutation { markAsSent } }", () => { } }); - const appendix2grouped = await prisma.form.findOne({ + const appendix2grouped = await prisma.form.findUnique({ where: { id: appendix2.id } }); expect(appendix2grouped.status).toEqual("GROUPED"); @@ -406,7 +408,7 @@ describe("{ mutation { markAsSent } }", () => { } }); - const appendix2grouped = await prisma.form.findOne({ + const appendix2grouped = await prisma.form.findUnique({ where: { id: appendix2.id } }); expect(appendix2grouped.status).toEqual("GROUPED"); diff --git a/back/src/forms/resolvers/mutations/__tests__/markAsTempStored.integration.ts b/back/src/forms/resolvers/mutations/__tests__/markAsTempStored.integration.ts index 9782decb53f..ae3f395242f 100644 --- a/back/src/forms/resolvers/mutations/__tests__/markAsTempStored.integration.ts +++ b/back/src/forms/resolvers/mutations/__tests__/markAsTempStored.integration.ts @@ -95,7 +95,7 @@ describe("{ mutation { markAsTempStored } }", () => { } }); - const formAfterMutation = await prisma.form.findOne({ + const formAfterMutation = await prisma.form.findUnique({ where: { id: form.id } }); @@ -143,7 +143,7 @@ describe("{ mutation { markAsTempStored } }", () => { }); const updatedTemporaryStorageDetail = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .temporaryStorageDetail(); expect( new Date(updatedTemporaryStorageDetail.tempStorerSignedAt).toDateString() @@ -185,7 +185,7 @@ describe("{ mutation { markAsTempStored } }", () => { } }); - const formAfterMutation = await prisma.form.findOne({ + const formAfterMutation = await prisma.form.findUnique({ where: { id: form.id } }); diff --git a/back/src/forms/resolvers/mutations/__tests__/markSegmentAsReadyToTakeOver.integration.ts b/back/src/forms/resolvers/mutations/__tests__/markSegmentAsReadyToTakeOver.integration.ts index ec1dbb16ac6..92f5d727ae4 100644 --- a/back/src/forms/resolvers/mutations/__tests__/markSegmentAsReadyToTakeOver.integration.ts +++ b/back/src/forms/resolvers/mutations/__tests__/markSegmentAsReadyToTakeOver.integration.ts @@ -50,7 +50,7 @@ describe("{ mutation { markSegmentAsReadyToTakeOver} }", () => { }` ); - const readyToTakeOverSegment = await prisma.transportSegment.findOne({ + const readyToTakeOverSegment = await prisma.transportSegment.findUnique({ where: { id: segment.id } }); expect(readyToTakeOverSegment.readyToTakeOver).toBe(true); diff --git a/back/src/forms/resolvers/mutations/__tests__/prepareSegment.integration.ts b/back/src/forms/resolvers/mutations/__tests__/prepareSegment.integration.ts index 76641e1368a..adb7b69e629 100644 --- a/back/src/forms/resolvers/mutations/__tests__/prepareSegment.integration.ts +++ b/back/src/forms/resolvers/mutations/__tests__/prepareSegment.integration.ts @@ -57,7 +57,7 @@ describe("{ mutation { prepareSegment } }", () => { }` ); - const segment = await prisma.transportSegment.findOne({ + const segment = await prisma.transportSegment.findUnique({ where: { id: data.prepareSegment.id } }); @@ -106,7 +106,7 @@ describe("{ mutation { prepareSegment } }", () => { }` ); - const segment = await prisma.transportSegment.findOne({ + const segment = await prisma.transportSegment.findUnique({ where: { id: data.prepareSegment.id } }); diff --git a/back/src/forms/resolvers/mutations/__tests__/signedByTransporter.integration.ts b/back/src/forms/resolvers/mutations/__tests__/signedByTransporter.integration.ts index 90d81787970..8350e44c3ac 100644 --- a/back/src/forms/resolvers/mutations/__tests__/signedByTransporter.integration.ts +++ b/back/src/forms/resolvers/mutations/__tests__/signedByTransporter.integration.ts @@ -58,7 +58,9 @@ describe("Mutation.signedByTransporter", () => { } }); - const resultingForm = await prisma.form.findOne({ where: { id: form.id } }); + const resultingForm = await prisma.form.findUnique({ + where: { id: form.id } + }); expect(resultingForm.status).toBe("SENT"); }); @@ -94,7 +96,9 @@ describe("Mutation.signedByTransporter", () => { } }); - const resultingForm = await prisma.form.findOne({ where: { id: form.id } }); + const resultingForm = await prisma.form.findUnique({ + where: { id: form.id } + }); expect(resultingForm.status).toBe("SENT"); }); @@ -402,7 +406,9 @@ describe("Mutation.signedByTransporter", () => { } }); - const resultingForm = await prisma.form.findOne({ where: { id: form.id } }); + const resultingForm = await prisma.form.findUnique({ + where: { id: form.id } + }); expect(resultingForm.status).toBe("RESENT"); }); }); diff --git a/back/src/forms/resolvers/mutations/__tests__/takeOverSegment.integration.ts b/back/src/forms/resolvers/mutations/__tests__/takeOverSegment.integration.ts index fdeb0ad0429..01ba746d64b 100644 --- a/back/src/forms/resolvers/mutations/__tests__/takeOverSegment.integration.ts +++ b/back/src/forms/resolvers/mutations/__tests__/takeOverSegment.integration.ts @@ -70,7 +70,7 @@ describe("{ mutation { takeOverSegment } }", () => { ); // segment take over fields are filled - const takenOverSegment = await prisma.transportSegment.findOne({ + const takenOverSegment = await prisma.transportSegment.findUnique({ where: { id: segment.id } }); @@ -80,7 +80,9 @@ describe("{ mutation { takeOverSegment } }", () => { expect(takenOverSegment.takenOverBy).toBe("transporter suivant"); // form next and currentTransporterSiret have been updated - const udpatedForm = await prisma.form.findOne({ where: { id: form.id } }); + const udpatedForm = await prisma.form.findUnique({ + where: { id: form.id } + }); expect(udpatedForm.currentTransporterSiret).toBe( secondTransporterCompany.siret ); diff --git a/back/src/forms/resolvers/mutations/__tests__/updateTransporterFields.integration.ts b/back/src/forms/resolvers/mutations/__tests__/updateTransporterFields.integration.ts index d76589dca2c..36b0e0faccb 100644 --- a/back/src/forms/resolvers/mutations/__tests__/updateTransporterFields.integration.ts +++ b/back/src/forms/resolvers/mutations/__tests__/updateTransporterFields.integration.ts @@ -39,7 +39,7 @@ describe("Forms -> updateTransporterFields mutation", () => { `; await mutate(mutation); - form = await prisma.form.findOne({ where: { id: form.id } }); + form = await prisma.form.findUnique({ where: { id: form.id } }); expect(form.transporterNumberPlate).toEqual("ZBLOP 83"); }); @@ -68,7 +68,7 @@ describe("Forms -> updateTransporterFields mutation", () => { `; await mutate(mutation); - form = await prisma.form.findOne({ where: { id: form.id } }); + form = await prisma.form.findUnique({ where: { id: form.id } }); expect(form.transporterCustomInfo).toEqual("tournée 493"); }); @@ -100,7 +100,7 @@ describe("Forms -> updateTransporterFields mutation", () => { "Ce champ n'est pas modifiable sur un bordereau qui n'est pas en statut scellé" ); - form = await prisma.form.findOne({ where: { id: form.id } }); + form = await prisma.form.findUnique({ where: { id: form.id } }); expect(form.transporterCustomInfo).toEqual(null); }); @@ -132,7 +132,7 @@ describe("Forms -> updateTransporterFields mutation", () => { "Vous n'êtes pas transporteur de ce bordereau." ); - form = await prisma.form.findOne({ where: { id: form.id } }); + form = await prisma.form.findUnique({ where: { id: form.id } }); expect(form.transporterCustomInfo).toEqual(null); }); diff --git a/back/src/forms/resolvers/mutations/createForm.ts b/back/src/forms/resolvers/mutations/createForm.ts index 606f518c5d6..298f341e605 100644 --- a/back/src/forms/resolvers/mutations/createForm.ts +++ b/back/src/forms/resolvers/mutations/createForm.ts @@ -1,4 +1,4 @@ -import { FormCreateInput, Status } from "@prisma/client"; +import { Prisma, Status } from "@prisma/client"; import prisma from "src/prisma"; import { checkIsAuthenticated } from "../../../common/permissions"; import { @@ -45,7 +45,7 @@ const createFormResolver = async ( } const form = flattenFormInput(formContent); - const formCreateInput: FormCreateInput = { + const formCreateInput: Prisma.FormCreateInput = { ...form, readableId: await getReadableId(), owner: { connect: { id: user.id } }, diff --git a/back/src/forms/resolvers/mutations/editSegment.integration.ts b/back/src/forms/resolvers/mutations/editSegment.integration.ts index 6c7bbfed436..a979688be75 100644 --- a/back/src/forms/resolvers/mutations/editSegment.integration.ts +++ b/back/src/forms/resolvers/mutations/editSegment.integration.ts @@ -61,7 +61,7 @@ describe("{ mutation { editSegment } }", () => { }` ); - const editedSegment = await prisma.transportSegment.findOne({ + const editedSegment = await prisma.transportSegment.findUnique({ where: { id: segment.id } }); expect(editedSegment.transporterCompanySiret).toBe("5678956789"); @@ -110,7 +110,7 @@ describe("{ mutation { editSegment } }", () => { }` ); - const editedSegment = await prisma.transportSegment.findOne({ + const editedSegment = await prisma.transportSegment.findUnique({ where: { id: segment.id } }); expect(editedSegment.transporterCompanySiret).toBe("5678956789"); @@ -166,7 +166,7 @@ describe("{ mutation { editSegment } }", () => { }` ); - const editedSegment = await prisma.transportSegment.findOne({ + const editedSegment = await prisma.transportSegment.findUnique({ where: { id: segment.id } }); diff --git a/back/src/forms/resolvers/mutations/importPaperForm.ts b/back/src/forms/resolvers/mutations/importPaperForm.ts index fde1540fef4..c3d40977fab 100644 --- a/back/src/forms/resolvers/mutations/importPaperForm.ts +++ b/back/src/forms/resolvers/mutations/importPaperForm.ts @@ -1,4 +1,4 @@ -import { Form, FormCreateInput, FormUpdateInput, User } from "@prisma/client"; +import { Form, Prisma, User } from "@prisma/client"; import { UserInputError } from "apollo-server-express"; import prisma from "src/prisma"; import { checkIsAuthenticated } from "../../../common/permissions"; @@ -56,7 +56,7 @@ async function updateForm(user: User, form: Form, input: ImportPaperFormInput) { ); } - const formUpdateInput: FormUpdateInput = { + const formUpdateInput: Prisma.FormUpdateInput = { ...flattenedFormInput, isImportedFromPaper: true, signedByTransporter: true @@ -89,7 +89,7 @@ async function createForm(user: User, input: ImportPaperFormInput) { ); } - const formCreateInput: FormCreateInput = { + const formCreateInput: Prisma.FormCreateInput = { ...flattenedFormInput, readableId: await getReadableId(), owner: { connect: { id: user.id } }, diff --git a/back/src/forms/resolvers/mutations/markAsProcessed.ts b/back/src/forms/resolvers/mutations/markAsProcessed.ts index b6f4a0c2bfd..68982052d52 100644 --- a/back/src/forms/resolvers/mutations/markAsProcessed.ts +++ b/back/src/forms/resolvers/mutations/markAsProcessed.ts @@ -1,4 +1,4 @@ -import { FormUpdateInput } from "@prisma/client"; +import { Prisma } from "@prisma/client"; import prisma from "src/prisma"; import { PROCESSING_OPERATIONS } from "../../../common/constants"; import { checkIsAuthenticated } from "../../../common/permissions"; @@ -26,7 +26,7 @@ const markAsProcessedResolver: MutationResolvers["markAsProcessed"] = async ( await checkCanMarkAsProcessed(user, form); - const formUpdateInput: FormUpdateInput = flattenProcessedFormInput( + const formUpdateInput: Prisma.FormUpdateInput = flattenProcessedFormInput( processedInfo ); await processedInfoSchema.validate(formUpdateInput); @@ -55,7 +55,7 @@ const markAsProcessedResolver: MutationResolvers["markAsProcessed"] = async ( // mark appendix2Forms as PROCESSED const appendix2Forms = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .appendix2Forms(); if (appendix2Forms.length > 0) { const promises = appendix2Forms.map(appendix => { diff --git a/back/src/forms/resolvers/mutations/markAsReceived.ts b/back/src/forms/resolvers/mutations/markAsReceived.ts index f3216a9492b..038b6746d71 100644 --- a/back/src/forms/resolvers/mutations/markAsReceived.ts +++ b/back/src/forms/resolvers/mutations/markAsReceived.ts @@ -26,7 +26,7 @@ const markAsReceivedResolver: MutationResolvers["markAsReceived"] = async ( // this form can be mark as received only if it has been // taken over by the transporter after temp storage const temporaryStorageDetail = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .temporaryStorageDetail(); if (!temporaryStorageDetail?.signedAt) { @@ -36,7 +36,7 @@ const markAsReceivedResolver: MutationResolvers["markAsReceived"] = async ( // check all multi-modal transport segments (if any) have been taken over const transportSegments = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .transportSegments(); if (transportSegments.length > 0) { const hasSegmentToTakeOver = transportSegments.some(f => !f.takenOverAt); diff --git a/back/src/forms/resolvers/mutations/markAsResealed.ts b/back/src/forms/resolvers/mutations/markAsResealed.ts index 62afef577da..50d03509971 100644 --- a/back/src/forms/resolvers/mutations/markAsResealed.ts +++ b/back/src/forms/resolvers/mutations/markAsResealed.ts @@ -24,7 +24,7 @@ const markAsResealed: MutationResolvers["markAsResealed"] = async ( const form = await getFormOrFormNotFound({ id }); const temporaryStorageDetail = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .temporaryStorageDetail(); if (temporaryStorageDetail === null) { diff --git a/back/src/forms/resolvers/mutations/markAsResent.ts b/back/src/forms/resolvers/mutations/markAsResent.ts index 95d14e50fa1..70bf92b2123 100644 --- a/back/src/forms/resolvers/mutations/markAsResent.ts +++ b/back/src/forms/resolvers/mutations/markAsResent.ts @@ -24,7 +24,7 @@ const markAsResentResolver: MutationResolvers["markAsResent"] = async ( if (form.status === "TEMP_STORED") { const temporaryStorageDetail = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .temporaryStorageDetail(); if (temporaryStorageDetail === null) { diff --git a/back/src/forms/resolvers/mutations/markAsSealed.ts b/back/src/forms/resolvers/mutations/markAsSealed.ts index 26b6dcfc110..3f73ead5f1e 100644 --- a/back/src/forms/resolvers/mutations/markAsSealed.ts +++ b/back/src/forms/resolvers/mutations/markAsSealed.ts @@ -25,7 +25,7 @@ const markAsSealedResolver: MutationResolvers["markAsSealed"] = async ( // mark appendix2Forms as GROUPED const appendix2Forms = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .appendix2Forms(); if (appendix2Forms.length > 0) { const promises = appendix2Forms.map(appendix => { diff --git a/back/src/forms/resolvers/mutations/markAsSent.ts b/back/src/forms/resolvers/mutations/markAsSent.ts index 8aaf90b87f2..da450054048 100644 --- a/back/src/forms/resolvers/mutations/markAsSent.ts +++ b/back/src/forms/resolvers/mutations/markAsSent.ts @@ -42,7 +42,7 @@ const markAsSentResolver: MutationResolvers["markAsSent"] = async ( // mark appendix2Forms as GROUPED const appendix2Forms = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .appendix2Forms({ where: { status: "AWAITING_GROUP" } }); if (appendix2Forms.length > 0) { diff --git a/back/src/forms/resolvers/mutations/multiModal.ts b/back/src/forms/resolvers/mutations/multiModal.ts index 276b1a45cc2..60ac9e7240f 100644 --- a/back/src/forms/resolvers/mutations/multiModal.ts +++ b/back/src/forms/resolvers/mutations/multiModal.ts @@ -91,7 +91,7 @@ type FormSiretsAndSegments = { }; const getForm = async formId => { - const form = await prisma.form.findOne({ + const form = await prisma.form.findUnique({ where: { id: formId }, include: { owner: { @@ -249,7 +249,7 @@ export async function markSegmentAsReadyToTakeOver( ): Promise { const user = checkIsAuthenticated(context); - const currentSegment = await prisma.transportSegment.findOne({ + const currentSegment = await prisma.transportSegment.findUnique({ where: { id }, include: { form: { @@ -306,7 +306,7 @@ export async function takeOverSegment( ); } - const currentSegment = await prisma.transportSegment.findOne({ + const currentSegment = await prisma.transportSegment.findUnique({ where: { id }, include: { form: { @@ -386,7 +386,7 @@ export async function editSegment( ): Promise { const user = checkIsAuthenticated(context); - const currentSegment = await prisma.transportSegment.findOne({ + const currentSegment = await prisma.transportSegment.findUnique({ where: { id }, include: { form: { diff --git a/back/src/forms/resolvers/mutations/signedByTransporter.ts b/back/src/forms/resolvers/mutations/signedByTransporter.ts index 842e0145785..4cd034cb240 100644 --- a/back/src/forms/resolvers/mutations/signedByTransporter.ts +++ b/back/src/forms/resolvers/mutations/signedByTransporter.ts @@ -73,7 +73,7 @@ const signedByTransporterResolver: MutationResolvers["signedByTransporter"] = as await checkSecurityCode(form.recipientCompanySiret, securityCode); const temporaryStorageDetail = await prisma.form - .findOne({ where: { id } }) + .findUnique({ where: { id } }) .temporaryStorageDetail(); const hasWasteDetailsOverride = !!temporaryStorageDetail.wasteDetailsQuantity; diff --git a/back/src/forms/resolvers/mutations/updateForm.ts b/back/src/forms/resolvers/mutations/updateForm.ts index c7802a89687..22a052affc5 100644 --- a/back/src/forms/resolvers/mutations/updateForm.ts +++ b/back/src/forms/resolvers/mutations/updateForm.ts @@ -3,7 +3,7 @@ import { flattenTemporaryStorageDetailInput, expandFormFromDb } from "../../form-converter"; -import { FormUpdateInput } from "@prisma/client"; +import { Prisma } from "@prisma/client"; import prisma from "src/prisma"; import { ResolversParentTypes, @@ -55,7 +55,7 @@ const updateFormResolver = async ( const form = flattenFormInput(formContent); // Construct form update payload - const formUpdateInput: FormUpdateInput = { + const formUpdateInput: Prisma.FormUpdateInput = { ...form, appendix2Forms: { set: appendix2Forms } }; @@ -69,7 +69,7 @@ const updateFormResolver = async ( formContent.recipient?.isTempStorage === true; const existingTemporaryStorageDetail = await prisma.form - .findOne({ where: { id } }) + .findUnique({ where: { id } }) .temporaryStorageDetail(); if ( diff --git a/back/src/forms/resolvers/queries/__tests__/form.integration.ts b/back/src/forms/resolvers/queries/__tests__/form.integration.ts index 37dabe62ab2..79390b33a0e 100644 --- a/back/src/forms/resolvers/queries/__tests__/form.integration.ts +++ b/back/src/forms/resolvers/queries/__tests__/form.integration.ts @@ -1,4 +1,4 @@ -import { Form as PrismaForm, FormCreateInput } from "@prisma/client"; +import { Form as PrismaForm, Prisma } from "@prisma/client"; import { resetDatabase } from "integration-tests/helper"; import { formFactory, @@ -16,7 +16,9 @@ const GET_FORM_QUERY = ` } `; -async function createForm(opts: Partial): Promise { +async function createForm( + opts: Partial +): Promise { const owner = await userFactory(); const form = await formFactory({ ownerId: owner.id, diff --git a/back/src/forms/resolvers/queries/__tests__/forms.integration.ts b/back/src/forms/resolvers/queries/__tests__/forms.integration.ts index c8f1340b04b..6768bec6bd6 100644 --- a/back/src/forms/resolvers/queries/__tests__/forms.integration.ts +++ b/back/src/forms/resolvers/queries/__tests__/forms.integration.ts @@ -1,5 +1,5 @@ import { addDays, format, subDays } from "date-fns"; -import { Form, FormCreateInput } from "@prisma/client"; +import { Form, Prisma } from "@prisma/client"; import { resetDatabase } from "integration-tests/helper"; import prisma from "src/prisma"; import { @@ -11,7 +11,10 @@ import { } from "../../../../__tests__/factories"; import makeClient from "../../../../__tests__/testClient"; -function createForms(userId: string, params: Partial[]) { +function createForms( + userId: string, + params: Partial[] +) { return Promise.all( params.map(p => { return formFactory({ @@ -24,7 +27,7 @@ function createForms(userId: string, params: Partial[]) { function createNForms( userId: string, - param: Partial, + param: Partial, n: number ) { return createForms(userId, Array(n).fill(param)); @@ -34,7 +37,7 @@ function createNForms( // strict ordering on the field `createdAt` async function createNSortedForms( userId: string, - opt: Partial, + opt: Partial, n: number ) { const forms: Form[] = []; diff --git a/back/src/forms/resolvers/queries/__tests__/formsRegister.integration.ts b/back/src/forms/resolvers/queries/__tests__/formsRegister.integration.ts index 3885c6bd833..d9362a7fe8a 100644 --- a/back/src/forms/resolvers/queries/__tests__/formsRegister.integration.ts +++ b/back/src/forms/resolvers/queries/__tests__/formsRegister.integration.ts @@ -204,7 +204,7 @@ describe("query { formsRegister }", () => { }); const tempStorageDetail = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .temporaryStorageDetail(); const { query } = makeClient(user); diff --git a/back/src/forms/resolvers/queries/forms.ts b/back/src/forms/resolvers/queries/forms.ts index 847d006025a..b429ed7edbe 100644 --- a/back/src/forms/resolvers/queries/forms.ts +++ b/back/src/forms/resolvers/queries/forms.ts @@ -2,7 +2,7 @@ import { getCompanyOrCompanyNotFound } from "../../../companies/database"; import { MissingSiret } from "../../../common/errors"; import { checkIsAuthenticated } from "../../../common/permissions"; import { QueryResolvers } from "../../../generated/graphql/types"; -import { Company } from "@prisma/client"; +import { Company, Status } from "@prisma/client"; import prisma from "src/prisma"; import { getUserCompanies } from "../../../users/database"; import { checkIsCompanyMember } from "../../../users/permissions"; @@ -78,7 +78,7 @@ function getHasNextStepFilter(siret: string, hasNextStep?: boolean | null) { const filter = { OR: [ // DRAFT - { status: "DRAFT" }, + { status: Status.DRAFT }, // isTemporaryStorer && (RESENT || RECEIVED) { AND: [ @@ -87,7 +87,7 @@ function getHasNextStepFilter(siret: string, hasNextStep?: boolean | null) { destinationCompanySiret: siret } }, - { OR: [{ status: "RESENT" }, { status: "RECEIVED" }] } + { OR: [{ status: Status.RESENT }, { status: Status.RECEIVED }] } ] }, // isRecipient && isTempStorage == isTempStorer @@ -97,7 +97,7 @@ function getHasNextStepFilter(siret: string, hasNextStep?: boolean | null) { { recipientCompanySiret: siret }, { recipientIsTempStorage: true }, { - OR: [{ status: "SENT" }, { status: "TEMP_STORED" }] + OR: [{ status: Status.SENT }, { status: Status.TEMP_STORED }] } ] }, @@ -108,9 +108,12 @@ function getHasNextStepFilter(siret: string, hasNextStep?: boolean | null) { { OR: [ { - AND: [{ status: "SENT" }, { recipientIsTempStorage: false }] + AND: [ + { status: Status.SENT }, + { recipientIsTempStorage: false } + ] }, - { status: "RECEIVED" } + { status: Status.RECEIVED } ] } ] diff --git a/back/src/forms/workflow/__tests__/diff.integration.ts b/back/src/forms/workflow/__tests__/diff.integration.ts index bf2228ce676..b17a4e57879 100644 --- a/back/src/forms/workflow/__tests__/diff.integration.ts +++ b/back/src/forms/workflow/__tests__/diff.integration.ts @@ -1,4 +1,4 @@ -import { FormUpdateInput } from "@prisma/client"; +import { Prisma } from "@prisma/client"; import { resetDatabase } from "integration-tests/helper"; import prisma from "src/prisma"; import { @@ -23,7 +23,7 @@ describe("formDiff", () => { it("should calculate diff between two different forms", async () => { const user = await userFactory(); const form = await formFactory({ ownerId: user.id }); - const formUpdateInput: FormUpdateInput = { + const formUpdateInput: Prisma.FormUpdateInput = { emitterCompanyName: "Updated name", // nested field sentBy: "Mr Sender" // shallow field }; @@ -42,9 +42,9 @@ describe("formDiff", () => { const user = await userFactory(); const form = await formWithTempStorageFactory({ ownerId: user.id }); const temporaryStorageDetail = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .temporaryStorageDetail(); - const formUpdateInput: FormUpdateInput = { + const formUpdateInput: Prisma.FormUpdateInput = { temporaryStorageDetail: { update: { transporterCompanyName: "New Transporter" @@ -56,7 +56,7 @@ describe("formDiff", () => { data: formUpdateInput }); const updatedTemporaryStorageDetail = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .temporaryStorageDetail(); const diff = formDiff( @@ -80,9 +80,9 @@ describe("formDiff", () => { const user = await userFactory(); const form = await formFactory({ ownerId: user.id }); const temporaryStorageDetail = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .temporaryStorageDetail(); - const formUpdateInput: FormUpdateInput = { + const formUpdateInput: Prisma.FormUpdateInput = { temporaryStorageDetail: { create: tempStorageData } @@ -92,7 +92,7 @@ describe("formDiff", () => { data: formUpdateInput }); const updatedTemporaryStorageDetail = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .temporaryStorageDetail(); const diff = formDiff( { ...form, temporaryStorageDetail }, diff --git a/back/src/forms/workflow/__tests__/transitionForm.integration.ts b/back/src/forms/workflow/__tests__/transitionForm.integration.ts index 8fca79d4ce6..2648d99b6a0 100644 --- a/back/src/forms/workflow/__tests__/transitionForm.integration.ts +++ b/back/src/forms/workflow/__tests__/transitionForm.integration.ts @@ -1,5 +1,5 @@ import { AuthType } from "../../../auth"; -import { FormUpdateInput } from "@prisma/client"; +import { Prisma } from "@prisma/client"; import { resetDatabase } from "integration-tests/helper"; import prisma from "src/prisma"; import { formFactory, userFactory } from "../../../__tests__/factories"; @@ -16,7 +16,7 @@ describe("transition form", () => { ownerId: owner.id, opt: { status: "SENT" } }); - const formUpdateInput: FormUpdateInput = { + const formUpdateInput: Prisma.FormUpdateInput = { receivedBy: "Bill", receivedAt: "2019-01-17T09:22:00.000Z", signedAt: "2019-01-17T09:22:00.000Z", @@ -27,7 +27,9 @@ describe("transition form", () => { const event = { type: EventType.MarkAsReceived, formUpdateInput }; await transitionForm({ ...user, auth: AuthType.Bearer }, form, event); - const updatedForm = await prisma.form.findOne({ where: { id: form.id } }); + const updatedForm = await prisma.form.findUnique({ + where: { id: form.id } + }); const nextStatus = "RECEIVED"; @@ -37,10 +39,10 @@ describe("transition form", () => { expect(statusLogs).toHaveLength(1); const statusLog = statusLogs[0]; const statusLogUser = await prisma.statusLog - .findOne({ where: { id: statusLog.id } }) + .findUnique({ where: { id: statusLog.id } }) .user(); const statusLogForm = await prisma.statusLog - .findOne({ where: { id: statusLog.id } }) + .findUnique({ where: { id: statusLog.id } }) .form(); expect(statusLog.status).toEqual(nextStatus); @@ -58,7 +60,7 @@ describe("transition form", () => { ownerId: owner.id, opt: { status: "DRAFT" } }); - const formUpdateInput: FormUpdateInput = { + const formUpdateInput: Prisma.FormUpdateInput = { receivedBy: "Bill", receivedAt: "2019-01-17T09:22:00.000Z", signedAt: "2019-01-17T09:22:00.000Z", diff --git a/back/src/forms/workflow/transitionForm.ts b/back/src/forms/workflow/transitionForm.ts index 8fe1c2cfc5a..079620422d7 100644 --- a/back/src/forms/workflow/transitionForm.ts +++ b/back/src/forms/workflow/transitionForm.ts @@ -1,4 +1,4 @@ -import { Form, FormUpdateInput, Status } from "@prisma/client"; +import { Form, Prisma, Status } from "@prisma/client"; import prisma from "src/prisma"; import { Event } from "./types"; import machine from "./machine"; @@ -29,7 +29,7 @@ export default async function transitionForm( const nextStatus = nextState.value as Status; - const formUpdateInput: FormUpdateInput = { + const formUpdateInput: Prisma.FormUpdateInput = { status: nextStatus, ...event.formUpdateInput }; @@ -37,7 +37,7 @@ export default async function transitionForm( // retrieves temp storage before update // for diff calculation const temporaryStorageDetail = await prisma.form - .findOne({ where: { id: form.id } }) + .findUnique({ where: { id: form.id } }) .temporaryStorageDetail(); // update form @@ -48,7 +48,7 @@ export default async function transitionForm( // retrieves updated temp storage const updatedTemporaryStorageDetail = await prisma.form - .findOne({ where: { id: updatedForm.id } }) + .findUnique({ where: { id: updatedForm.id } }) .temporaryStorageDetail(); // calculates diff between initial form and updated form diff --git a/back/src/forms/workflow/types.ts b/back/src/forms/workflow/types.ts index ee8a6820d76..13acb0efa38 100644 --- a/back/src/forms/workflow/types.ts +++ b/back/src/forms/workflow/types.ts @@ -1,4 +1,4 @@ -import { FormUpdateInput } from "@prisma/client"; +import { Prisma } from "@prisma/client"; // Xstate possible states export enum FormState { @@ -33,5 +33,5 @@ export enum EventType { // Xstate event export type Event = { type: EventType; - formUpdateInput?: FormUpdateInput; + formUpdateInput?: Prisma.FormUpdateInput; }; diff --git a/back/src/oauth2.ts b/back/src/oauth2.ts index e1db8916319..6b71a34a1d2 100644 --- a/back/src/oauth2.ts +++ b/back/src/oauth2.ts @@ -17,7 +17,7 @@ export const oauth2server = createServer(); oauth2server.serializeClient((client, done) => done(null, client.id)); oauth2server.deserializeClient(async (id, done) => { - const client = await prisma.application.findOne({ where: { id } }); + const client = await prisma.application.findUnique({ where: { id } }); return done(null, client); }); diff --git a/back/src/routers/auth-router.ts b/back/src/routers/auth-router.ts index 76e0b1c9a79..d8d25651924 100644 --- a/back/src/routers/auth-router.ts +++ b/back/src/routers/auth-router.ts @@ -1,4 +1,4 @@ -import express from "express"; +import { Router } from "express"; import passport from "passport"; import querystring from "querystring"; import { getUIBaseURL } from "../utils"; @@ -7,7 +7,7 @@ import nocache from "../common/middlewares/nocache"; const UI_BASE_URL = getUIBaseURL(); -const authRouter = express.Router(); +const authRouter = Router(); authRouter.post("/login", (req, res, next) => { passport.authenticate("local", (err, user, info) => { if (err) { diff --git a/back/src/routers/oauth2-router.ts b/back/src/routers/oauth2-router.ts index 6ce2f9f9f5f..c7751e148fb 100644 --- a/back/src/routers/oauth2-router.ts +++ b/back/src/routers/oauth2-router.ts @@ -1,11 +1,11 @@ import prisma from "src/prisma"; -import express, { Request, Response } from "express"; +import { Router, Request, Response } from "express"; import passport from "passport"; import { oauth2server } from "../oauth2"; import ensureLoggedIn from "../common/middlewares/ensureLoggedIn"; import { OAuth2, AuthorizationError } from "oauth2orize"; -export const oauth2Router = express.Router(); +export const oauth2Router = Router(); // User authorization endpoint. @@ -18,7 +18,7 @@ oauth2Router.get( "/oauth2/authorize", ensureLoggedIn, oauth2server.authorization(async (clientId, redirectUri, done) => { - const client = await prisma.application.findOne({ + const client = await prisma.application.findUnique({ where: { id: clientId } }); if (!client) { diff --git a/back/src/scripts/bin/deleteUser.ts b/back/src/scripts/bin/deleteUser.ts index 47d6b052e58..e7dc15315df 100644 --- a/back/src/scripts/bin/deleteUser.ts +++ b/back/src/scripts/bin/deleteUser.ts @@ -21,7 +21,7 @@ import deleteUser from "../prisma/deleteUser"; return; } - const user = await prisma.user.findOne({ where: { id: userID } }); + const user = await prisma.user.findUnique({ where: { id: userID } }); if (!user) { console.log( diff --git a/back/src/scripts/bin/mergeUsersAndDelete.ts b/back/src/scripts/bin/mergeUsersAndDelete.ts index 9df9a5bf48b..cb3cc4b16b2 100644 --- a/back/src/scripts/bin/mergeUsersAndDelete.ts +++ b/back/src/scripts/bin/mergeUsersAndDelete.ts @@ -21,8 +21,8 @@ import deleteUser from "../prisma/deleteUser"; return; } - const user = await prisma.user.findOne({ where: { id: userID } }); - const heir = await prisma.user.findOne({ where: { id: heirUserID } }); + const user = await prisma.user.findUnique({ where: { id: userID } }); + const heir = await prisma.user.findUnique({ where: { id: heirUserID } }); if (!user) { console.log( diff --git a/back/src/scripts/prisma/__tests__/acceptPendingInvitations.integration.ts b/back/src/scripts/prisma/__tests__/acceptPendingInvitations.integration.ts index 56eecebffbc..63d08b4c83a 100644 --- a/back/src/scripts/prisma/__tests__/acceptPendingInvitations.integration.ts +++ b/back/src/scripts/prisma/__tests__/acceptPendingInvitations.integration.ts @@ -24,7 +24,7 @@ describe("acceptPendingInvitations", () => { } }); await acceptPendingInvitations(); - const untouchedInvitation = await prisma.userAccountHash.findOne({ + const untouchedInvitation = await prisma.userAccountHash.findUnique({ where: { id: invitation.id } @@ -48,7 +48,7 @@ describe("acceptPendingInvitations", () => { } }); await acceptPendingInvitations(); - const deletedInvitation = await prisma.userAccountHash.findOne({ + const deletedInvitation = await prisma.userAccountHash.findUnique({ where: { id: invitation.id } @@ -72,7 +72,7 @@ describe("acceptPendingInvitations", () => { } }); await acceptPendingInvitations(); - const acceptedInvitation = await prisma.userAccountHash.findOne({ + const acceptedInvitation = await prisma.userAccountHash.findUnique({ where: { id: invitation.id } diff --git a/back/src/scripts/prisma/__tests__/deleteUser.integration.ts b/back/src/scripts/prisma/__tests__/deleteUser.integration.ts index 8235f6a41f4..eb75068ef50 100644 --- a/back/src/scripts/prisma/__tests__/deleteUser.integration.ts +++ b/back/src/scripts/prisma/__tests__/deleteUser.integration.ts @@ -17,7 +17,7 @@ describe("deleteUser", () => { await deleteUser(user); - const deletedUser = await prisma.user.findOne({ where: { id: user.id } }); + const deletedUser = await prisma.user.findUnique({ where: { id: user.id } }); expect(deletedUser).toBe(null); }); diff --git a/back/src/scripts/prisma/__tests__/mergeUsers.integration.ts b/back/src/scripts/prisma/__tests__/mergeUsers.integration.ts index 2050f6b13f4..49b6d449df5 100644 --- a/back/src/scripts/prisma/__tests__/mergeUsers.integration.ts +++ b/back/src/scripts/prisma/__tests__/mergeUsers.integration.ts @@ -24,7 +24,7 @@ describe("mergeUsers", () => { await mergeUsers(user, heir); - const updatedForm = await prisma.form.findOne({ + const updatedForm = await prisma.form.findUnique({ where: { id: form.id }, include: { owner: { select: { id: true } } } }); @@ -43,7 +43,7 @@ describe("mergeUsers", () => { await mergeUsers(user, heir); - const updatedStatusLog = await prisma.statusLog.findOne({ + const updatedStatusLog = await prisma.statusLog.findUnique({ where: { id: statusLog.id }, include: { user: { select: { id: true } } } }); @@ -95,7 +95,7 @@ describe("mergeUsers", () => { await mergeUsers(user, heir); - const updatedAccessToken = await prisma.accessToken.findOne({ + const updatedAccessToken = await prisma.accessToken.findUnique({ where: { id: accessToken.id }, include: { user: { select: { id: true } } } }); @@ -121,7 +121,7 @@ describe("mergeUsers", () => { await mergeUsers(user, heir); - const updatedApplication = await prisma.application.findOne({ + const updatedApplication = await prisma.application.findUnique({ where: { id: application.id }, diff --git a/back/src/scripts/prisma/__tests__/set-company-name.integration.ts b/back/src/scripts/prisma/__tests__/set-company-name.integration.ts index d33aa8e7e73..3e3c288d8b1 100644 --- a/back/src/scripts/prisma/__tests__/set-company-name.integration.ts +++ b/back/src/scripts/prisma/__tests__/set-company-name.integration.ts @@ -59,19 +59,19 @@ describe.skip("setCompanyName", () => { await setCompanyName(); // Frontier name was already set, it should be unchanged - const frontierUpdated = await prisma.company.findOne({ + const frontierUpdated = await prisma.company.findUnique({ where: { siret: frontier.siret } }); expect(frontierUpdated.name).toEqual(frontier.name); // LP name should be set - const lpUpdated = await prisma.company.findOne({ + const lpUpdated = await prisma.company.findUnique({ where: { siret: lp.siret } }); expect(lpUpdated.name).toEqual("LP"); // Code en Stock name should be set - const codeEnStockUpdated = await prisma.company.findOne({ + const codeEnStockUpdated = await prisma.company.findUnique({ where: { siret: codeEnStock.siret } @@ -79,7 +79,7 @@ describe.skip("setCompanyName", () => { expect(codeEnStockUpdated.name).toEqual("CODE EN STOCK"); // Unknown company name should not be set - const unknownUpdated = await prisma.company.findOne({ + const unknownUpdated = await prisma.company.findUnique({ where: { siret: unknown.siret } diff --git a/back/src/scripts/prisma/acceptPendingInvitations.ts b/back/src/scripts/prisma/acceptPendingInvitations.ts index e8ffbeb506a..a8683f5258c 100644 --- a/back/src/scripts/prisma/acceptPendingInvitations.ts +++ b/back/src/scripts/prisma/acceptPendingInvitations.ts @@ -7,7 +7,7 @@ import { associateUserToCompany } from "../../users/database"; export default async function acceptPendingInvitations() { const invitations = await prisma.userAccountHash.findMany(); for (const invitation of invitations) { - const user = await prisma.user.findOne({ + const user = await prisma.user.findUnique({ where: { email: invitation.email } }); if (user) { diff --git a/back/src/scripts/prisma/deleteUser.ts b/back/src/scripts/prisma/deleteUser.ts index a5f51741251..0fd099a7f97 100644 --- a/back/src/scripts/prisma/deleteUser.ts +++ b/back/src/scripts/prisma/deleteUser.ts @@ -1,4 +1,4 @@ -import { User, UserRole } from "@prisma/client"; +import { User } from "@prisma/client"; import prisma from "src/prisma"; export default async function deleteUser(user: User) { @@ -121,7 +121,7 @@ async function checkApplications(user: User): Promise { } }); for (const application of applications) { - const { admins } = await prisma.application.findOne({ + const { admins } = await prisma.application.findUnique({ where: { id: application.id }, include: { admins: { select: { id: true } } } }); diff --git a/back/src/scripts/prisma/mergeUsers.ts b/back/src/scripts/prisma/mergeUsers.ts index 55ab06ca141..e77310028ac 100644 --- a/back/src/scripts/prisma/mergeUsers.ts +++ b/back/src/scripts/prisma/mergeUsers.ts @@ -1,4 +1,4 @@ -import { User, UserRole } from "@prisma/client"; +import { User } from "@prisma/client"; import prisma from "src/prisma"; export default async function mergeUsers(user: User, heir: User) { diff --git a/back/src/server.ts b/back/src/server.ts index 0f5b9361ada..d22f1fc6882 100644 --- a/back/src/server.ts +++ b/back/src/server.ts @@ -1,35 +1,35 @@ import { CaptureConsole } from "@sentry/integrations"; import { + ApolloError, ApolloServer, makeExecutableSchema, - ApolloError, UserInputError } from "apollo-server-express"; +import { json, urlencoded } from "body-parser"; +import redisStore from "connect-redis"; +import cors from "cors"; import express from "express"; -import passport from "passport"; -import session from "express-session"; import rateLimit from "express-rate-limit"; -import RateLimitRedisStore from "rate-limit-redis"; -import redisStore from "connect-redis"; +import session from "express-session"; import depthLimit from "graphql-depth-limit"; -import bodyParser from "body-parser"; -import cors from "cors"; -import graphqlBodyParser from "./common/middlewares/graphqlBodyParser"; import { applyMiddleware } from "graphql-middleware"; import { sentry } from "graphql-middleware-sentry"; -import { authRouter } from "./routers/auth-router"; -import { downloadFileHandler } from "./common/file-download"; -import { oauth2Router } from "./routers/oauth2-router"; +import passport from "passport"; +import RateLimitRedisStore from "rate-limit-redis"; import prisma from "src/prisma"; -import { userActivationHandler } from "./users/activation"; -import { typeDefs, resolvers } from "./schema"; -import { getUIBaseURL } from "./utils"; import { passportBearerMiddleware, passportJwtMiddleware } from "./auth"; -import { GraphQLContext } from "./types"; import { ErrorCode } from "./common/errors"; -import { redisClient } from "./common/redis"; -import loggingMiddleware from "./common/middlewares/loggingMiddleware"; +import { downloadFileHandler } from "./common/file-download"; import errorHandler from "./common/middlewares/errorHandler"; +import graphqlBodyParser from "./common/middlewares/graphqlBodyParser"; +import loggingMiddleware from "./common/middlewares/loggingMiddleware"; +import { redisClient } from "./common/redis"; +import { authRouter } from "./routers/auth-router"; +import { oauth2Router } from "./routers/oauth2-router"; +import { resolvers, typeDefs } from "./schema"; +import { GraphQLContext } from "./types"; +import { userActivationHandler } from "./users/activation"; +import { getUIBaseURL } from "./utils"; const { SENTRY_DSN, @@ -158,9 +158,9 @@ app.use( * parse application/x-www-form-urlencoded * used when submitting login form */ -app.use(bodyParser.urlencoded({ extended: false })); +app.use(urlencoded({ extended: false })); -app.use(bodyParser.json()); +app.use(json()); // allow application/graphql header app.use(graphqlBodyParser); diff --git a/back/src/users/activation.ts b/back/src/users/activation.ts index d98e45c66d3..a3baf13a01f 100644 --- a/back/src/users/activation.ts +++ b/back/src/users/activation.ts @@ -9,7 +9,7 @@ export const userActivationHandler = async (req, res) => { } const user = await prisma.userActivationHash - .findOne({ where: { hash } }) + .findUnique({ where: { hash } }) .user(); if (user == null) { res.status(500).send("Hash invalide."); diff --git a/back/src/users/bulk-creation/__tests__/bulk-create.integration.ts b/back/src/users/bulk-creation/__tests__/bulk-create.integration.ts index 4f68fd23cda..26c4cdb4ceb 100644 --- a/back/src/users/bulk-creation/__tests__/bulk-create.integration.ts +++ b/back/src/users/bulk-creation/__tests__/bulk-create.integration.ts @@ -87,14 +87,14 @@ describe("bulk create users and companies from csv files", () => { await expectNumberOfRecords(2, 3, 4); // check fields are OK for first user - const john = await prisma.user.findOne({ + const john = await prisma.user.findUnique({ where: { email: "john.snow@trackdechets.fr" } }); expect(john.name).toEqual("john.snow@trackdechets.fr"); expect(john.isActive).toEqual(true); // check fields are OK for first company - const codeEnStock = await prisma.company.findOne({ + const codeEnStock = await prisma.company.findUnique({ where: { siret: "85001946400013" } }); expect(codeEnStock.name).toEqual("NAME FROM SIRENE"); @@ -116,7 +116,7 @@ describe("bulk create users and companies from csv files", () => { // Code en stock should be untouched expect( - await prisma.company.findOne({ where: { siret: "85001946400013" } }) + await prisma.company.findUnique({ where: { siret: "85001946400013" } }) ).toEqual(codeEnStock); }, 10000); @@ -130,7 +130,7 @@ describe("bulk create users and companies from csv files", () => { // john snow user should be untouched expect( - await prisma.user.findOne({ + await prisma.user.findUnique({ where: { email: "john.snow@trackdechets.fr" } }) ).toEqual(john); @@ -160,13 +160,13 @@ describe("bulk create users and companies from csv files", () => { await expectNumberOfRecords(2, 3, 4); // John Snow should be untouched - expect(await prisma.user.findOne({ where: { email: john.email } })).toEqual( - john - ); + expect( + await prisma.user.findUnique({ where: { email: john.email } }) + ).toEqual(john); // Code en Stock should be untouched expect( - await prisma.company.findOne({ where: { siret: codeEnStock.siret } }) + await prisma.company.findUnique({ where: { siret: codeEnStock.siret } }) ).toEqual(codeEnStock); // Association should be there const associations = await prisma.companyAssociation.findMany({ @@ -194,7 +194,7 @@ describe("bulk create users and companies from csv files", () => { await expectNumberOfRecords(3, 3, 5); // John Snow user should be created - const john = await prisma.user.findOne({ + const john = await prisma.user.findUnique({ where: { email: "john.snow@trackdechets.fr" } }); @@ -207,7 +207,7 @@ describe("bulk create users and companies from csv files", () => { expect(associations[0].role).toEqual("MEMBER"); // invitation should be marked as joined - const updatedInvitation = await prisma.userAccountHash.findOne({ + const updatedInvitation = await prisma.userAccountHash.findUnique({ where: { id: invitation.id } @@ -230,7 +230,7 @@ describe("bulk create users and companies from csv files", () => { await bulkCreateIdempotent(); await expectNumberOfRecords(2, 3, 4); - const john = await prisma.user.findOne({ + const john = await prisma.user.findUnique({ where: { email: "john.snow@trackdechets.fr" } }); @@ -242,7 +242,7 @@ describe("bulk create users and companies from csv files", () => { expect(associations[0].role).toEqual("MEMBER"); // invitation should be marked as joined - const updatedInvitation = await prisma.userAccountHash.findOne({ + const updatedInvitation = await prisma.userAccountHash.findUnique({ where: { id: invitation.id } diff --git a/back/src/users/bulk-creation/index.ts b/back/src/users/bulk-creation/index.ts index 47eae015fa9..737641ae52b 100644 --- a/back/src/users/bulk-creation/index.ts +++ b/back/src/users/bulk-creation/index.ts @@ -120,7 +120,7 @@ export async function bulkCreate(opts: Opts): Promise { // create companies in Trackdéchets for (const company of sirenifiedCompanies) { - const existingCompany = await prisma.company.findOne({ + const existingCompany = await prisma.company.findUnique({ where: { siret: company.siret } }); if (!existingCompany) { @@ -147,7 +147,7 @@ export async function bulkCreate(opts: Opts): Promise { for (const email of Object.keys(usersWithRoles)) { // check for existing user - let user = await prisma.user.findOne({ where: { email } }); + let user = await prisma.user.findUnique({ where: { email } }); let newUser = null; diff --git a/back/src/users/database.ts b/back/src/users/database.ts index cfc4b4afc15..cd13b20f908 100644 --- a/back/src/users/database.ts +++ b/back/src/users/database.ts @@ -6,10 +6,8 @@ import prisma from "src/prisma"; import { User, UserRole, - UserAccountHashWhereInput, - CompanyAssociationWhereInput, + Prisma, Company, - MembershipRequestWhereUniqueInput, UserAccountHash } from "@prisma/client"; import { FullUser } from "./types"; @@ -19,12 +17,12 @@ import { getUid, sanitizeEmail } from "../utils"; export async function getUserCompanies(userId: string): Promise { const companyAssociations = await prisma.user - .findOne({ where: { id: userId } }) + .findUnique({ where: { id: userId } }) .companyAssociations(); return Promise.all( companyAssociations.map(association => { return prisma.companyAssociation - .findOne({ where: { id: association.id } }) + .findUnique({ where: { id: association.id } }) .company(); }) ); @@ -116,7 +114,7 @@ export async function associateUserToCompany(userId, siret, role) { } export async function getUserAccountHashOrNotFound( - where: UserAccountHashWhereInput + where: Prisma.UserAccountHashWhereInput ) { const userAccountHashes = await prisma.userAccountHash.findMany({ where @@ -128,7 +126,7 @@ export async function getUserAccountHashOrNotFound( } export async function getCompanyAssociationOrNotFound( - where: CompanyAssociationWhereInput + where: Prisma.CompanyAssociationWhereInput ) { const companyAssociations = await prisma.companyAssociation.findMany({ where @@ -195,9 +193,11 @@ export async function acceptNewUserCompanyInvitations(user: User) { } export async function getMembershipRequestOrNotFoundError( - where: MembershipRequestWhereUniqueInput + where: Prisma.MembershipRequestWhereUniqueInput ) { - const membershipRequest = await prisma.membershipRequest.findOne({ where }); + const membershipRequest = await prisma.membershipRequest.findUnique({ + where + }); if (!membershipRequest) { throw new UserInputError("Cette demande de rattachement n'existe pas"); } diff --git a/back/src/users/resolvers/mutations/__tests__/acceptMembershipRequest.integration.ts b/back/src/users/resolvers/mutations/__tests__/acceptMembershipRequest.integration.ts index c3781fc74bd..d8253ec5151 100644 --- a/back/src/users/resolvers/mutations/__tests__/acceptMembershipRequest.integration.ts +++ b/back/src/users/resolvers/mutations/__tests__/acceptMembershipRequest.integration.ts @@ -130,11 +130,13 @@ describe("mutation acceptMembershipRequest", () => { const members = data.acceptMembershipRequest.users.map(u => u.email); expect(members).toContain(user.email); - const acceptedMembershipRequest = await prisma.membershipRequest.findOne({ - where: { - id: membershipRequest.id + const acceptedMembershipRequest = await prisma.membershipRequest.findUnique( + { + where: { + id: membershipRequest.id + } } - }); + ); expect(acceptedMembershipRequest.status).toEqual("ACCEPTED"); expect(acceptedMembershipRequest.statusUpdatedBy).toEqual(user.email); diff --git a/back/src/users/resolvers/mutations/__tests__/changePassword.integration.ts b/back/src/users/resolvers/mutations/__tests__/changePassword.integration.ts index a9d01bdd0fa..90630df986d 100644 --- a/back/src/users/resolvers/mutations/__tests__/changePassword.integration.ts +++ b/back/src/users/resolvers/mutations/__tests__/changePassword.integration.ts @@ -24,7 +24,9 @@ describe("mutation changePassword", () => { variables: { oldPassword: "pass", newPassword } }); expect(data.changePassword.id).toEqual(user.id); - const updatedUser = await prisma.user.findOne({ where: { id: user.id } }); + const updatedUser = await prisma.user.findUnique({ + where: { id: user.id } + }); expect(await compare(newPassword, updatedUser.password)).toEqual(true); }); }); diff --git a/back/src/users/resolvers/mutations/__tests__/editProfile.integration.ts b/back/src/users/resolvers/mutations/__tests__/editProfile.integration.ts index 42557b2a2a8..800e9ec1f03 100644 --- a/back/src/users/resolvers/mutations/__tests__/editProfile.integration.ts +++ b/back/src/users/resolvers/mutations/__tests__/editProfile.integration.ts @@ -23,7 +23,9 @@ describe("mutation editProfile", () => { const email = "newemail@trackdechets.fr"; const phone = "01234567891"; await mutate(EDIT_PROFILE, { variables: { name, email, phone } }); - const updatedUser = await prisma.user.findOne({ where: { id: user.id } }); + const updatedUser = await prisma.user.findUnique({ + where: { id: user.id } + }); expect(updatedUser.name).toEqual(name); expect(updatedUser.email).toEqual(email); expect(updatedUser.phone).toEqual(phone); diff --git a/back/src/users/resolvers/mutations/__tests__/inviteUserToCompany.integration.ts b/back/src/users/resolvers/mutations/__tests__/inviteUserToCompany.integration.ts index d8c2187cd02..d7f2dfefe8c 100644 --- a/back/src/users/resolvers/mutations/__tests__/inviteUserToCompany.integration.ts +++ b/back/src/users/resolvers/mutations/__tests__/inviteUserToCompany.integration.ts @@ -40,12 +40,12 @@ describe("mutation inviteUserToCompany", () => { expect.arrayContaining([{ email: admin.email }, { email: user.email }]) ); const companyAssociations = await prisma.user - .findOne({ where: { id: user.id } }) + .findUnique({ where: { id: user.id } }) .companyAssociations(); expect(companyAssociations).toHaveLength(1); expect(companyAssociations[0].role).toEqual("MEMBER"); const userCompany = await prisma.companyAssociation - .findOne({ + .findUnique({ where: { id: companyAssociations[0].id } diff --git a/back/src/users/resolvers/mutations/__tests__/joinWithInvite.integration.ts b/back/src/users/resolvers/mutations/__tests__/joinWithInvite.integration.ts index 39651bd5e9a..2b849e28a2e 100644 --- a/back/src/users/resolvers/mutations/__tests__/joinWithInvite.integration.ts +++ b/back/src/users/resolvers/mutations/__tests__/joinWithInvite.integration.ts @@ -80,7 +80,7 @@ describe("joinWithInvite mutation", () => { expect(data.joinWithInvite.email).toEqual(invitee); // should mark invitation as joined - const updatedInvitation = await prisma.userAccountHash.findOne({ + const updatedInvitation = await prisma.userAccountHash.findUnique({ where: { id: invitation.id } @@ -129,14 +129,14 @@ describe("joinWithInvite mutation", () => { } }); - const updatedInvitation2 = await prisma.userAccountHash.findOne({ + const updatedInvitation2 = await prisma.userAccountHash.findUnique({ where: { id: invitation2.id } }); expect(updatedInvitation2.acceptedAt).not.toBeNull(); - const user = await prisma.user.findOne({ where: { email: invitee } }); + const user = await prisma.user.findUnique({ where: { email: invitee } }); const companies = await getUserCompanies(user.id); expect(companies.length).toEqual(2); diff --git a/back/src/users/resolvers/mutations/__tests__/login.integration.ts b/back/src/users/resolvers/mutations/__tests__/login.integration.ts index dbac3436bdd..22c21c6e9cf 100644 --- a/back/src/users/resolvers/mutations/__tests__/login.integration.ts +++ b/back/src/users/resolvers/mutations/__tests__/login.integration.ts @@ -17,7 +17,7 @@ describe("{ mutation { login } }", () => { const { data } = await mutate(mutation); expect(data.login.token).toHaveLength(40); // should have created an accessToken in db - const accessToken = await prisma.accessToken.findOne({ + const accessToken = await prisma.accessToken.findUnique({ where: { token: data.login.token } diff --git a/back/src/users/resolvers/mutations/__tests__/refuseMembershipRequest.integration.ts b/back/src/users/resolvers/mutations/__tests__/refuseMembershipRequest.integration.ts index e6f8cf2ea28..bfdb42e4020 100644 --- a/back/src/users/resolvers/mutations/__tests__/refuseMembershipRequest.integration.ts +++ b/back/src/users/resolvers/mutations/__tests__/refuseMembershipRequest.integration.ts @@ -126,7 +126,7 @@ describe("mutation refuseMembershipRequest", () => { variables: { id: membershipRequest.id } }); expect(data.refuseMembershipRequest.users).toHaveLength(1); - const refusedMembershipRequest = await prisma.membershipRequest.findOne({ + const refusedMembershipRequest = await prisma.membershipRequest.findUnique({ where: { id: membershipRequest.id } diff --git a/back/src/users/resolvers/mutations/__tests__/sendMembershipRequest.integration.ts b/back/src/users/resolvers/mutations/__tests__/sendMembershipRequest.integration.ts index 5522a712a56..21ceabffb74 100644 --- a/back/src/users/resolvers/mutations/__tests__/sendMembershipRequest.integration.ts +++ b/back/src/users/resolvers/mutations/__tests__/sendMembershipRequest.integration.ts @@ -56,19 +56,19 @@ describe("mutation sendMembershipRequest", () => { expect(sentTo).toEqual(["jo****@trackdechets.fr"]); expect(email).toEqual(requester.email); expect(siret).toEqual(company.siret); - const membershipRequest = await prisma.membershipRequest.findOne({ + const membershipRequest = await prisma.membershipRequest.findUnique({ where: { id } }); // check relation to user was created const linkedUser = await prisma.membershipRequest - .findOne({ where: { id } }) + .findUnique({ where: { id } }) .user(); expect(linkedUser.id).toEqual(requester.id); // check relation to company was created const linkedCompany = await prisma.membershipRequest - .findOne({ where: { id } }) + .findUnique({ where: { id } }) .company(); expect(linkedCompany.id).toEqual(company.id); diff --git a/back/src/users/resolvers/mutations/__tests__/signup.integration.ts b/back/src/users/resolvers/mutations/__tests__/signup.integration.ts index ed140690665..84b756ce6fe 100644 --- a/back/src/users/resolvers/mutations/__tests__/signup.integration.ts +++ b/back/src/users/resolvers/mutations/__tests__/signup.integration.ts @@ -50,7 +50,9 @@ describe("Mutation.signup", () => { }); expect(data.signup).toEqual(user); - const newUser = await prisma.user.findOne({ where: { email: user.email } }); + const newUser = await prisma.user.findUnique({ + where: { email: user.email } + }); expect(newUser.email).toEqual(user.email); const activationHashes = await prisma.userActivationHash.findMany({ @@ -166,9 +168,11 @@ describe("Mutation.signup", () => { } }); - const newUser = await prisma.user.findOne({ where: { email: user.email } }); + const newUser = await prisma.user.findUnique({ + where: { email: user.email } + }); - const updatedInvitation = await prisma.userAccountHash.findOne({ + const updatedInvitation = await prisma.userAccountHash.findUnique({ where: { id: invitation.id } diff --git a/back/src/users/resolvers/mutations/acceptMembershipRequest.ts b/back/src/users/resolvers/mutations/acceptMembershipRequest.ts index 6a88b57b114..e4e0501056d 100644 --- a/back/src/users/resolvers/mutations/acceptMembershipRequest.ts +++ b/back/src/users/resolvers/mutations/acceptMembershipRequest.ts @@ -28,7 +28,7 @@ const acceptMembershipRequestResolver: MutationResolvers["acceptMembershipReques const membershipRequest = await getMembershipRequestOrNotFoundError({ id }); const company = await prisma.membershipRequest - .findOne({ where: { id: membershipRequest.id } }) + .findUnique({ where: { id: membershipRequest.id } }) .company(); // check authenticated user is admin of the company @@ -45,7 +45,7 @@ const acceptMembershipRequestResolver: MutationResolvers["acceptMembershipReques } const requester = await prisma.membershipRequest - .findOne({ where: { id: membershipRequest.id } }) + .findUnique({ where: { id: membershipRequest.id } }) .user(); // associate membership requester to company with the role decided by the admin @@ -62,7 +62,9 @@ const acceptMembershipRequestResolver: MutationResolvers["acceptMembershipReques // notify requester of acceptance await sendMail(userMails.membershipRequestAccepted(requester, company)); - const dbCompany = await prisma.company.findOne({ where: { id: company.id } }); + const dbCompany = await prisma.company.findUnique({ + where: { id: company.id } + }); return convertUrls(dbCompany); }; diff --git a/back/src/users/resolvers/mutations/changePassword.ts b/back/src/users/resolvers/mutations/changePassword.ts index e6637697e46..b1e9abdea39 100644 --- a/back/src/users/resolvers/mutations/changePassword.ts +++ b/back/src/users/resolvers/mutations/changePassword.ts @@ -16,7 +16,7 @@ export async function changePasswordFn( userId: string, { oldPassword, newPassword }: MutationChangePasswordArgs ) { - const user = await prisma.user.findOne({ where: { id: userId } }); + const user = await prisma.user.findUnique({ where: { id: userId } }); const passwordValid = await compare(oldPassword, user.password); if (!passwordValid) { throw new UserInputError("L'ancien mot de passe est incorrect.", { diff --git a/back/src/users/resolvers/mutations/deleteInvitation.ts b/back/src/users/resolvers/mutations/deleteInvitation.ts index e4022632ca7..d8b6d673bc2 100644 --- a/back/src/users/resolvers/mutations/deleteInvitation.ts +++ b/back/src/users/resolvers/mutations/deleteInvitation.ts @@ -23,7 +23,7 @@ const deleteInvitationResolver: MutationResolvers["deleteInvitation"] = async ( companySiret: siret }); await prisma.userAccountHash.delete({ where: { id: hash.id } }); - const dbCompany = await prisma.company.findOne({ where: { siret } }); + const dbCompany = await prisma.company.findUnique({ where: { siret } }); return convertUrls(dbCompany); }; diff --git a/back/src/users/resolvers/mutations/inviteUserToCompany.ts b/back/src/users/resolvers/mutations/inviteUserToCompany.ts index 6104346730d..7a61124d036 100644 --- a/back/src/users/resolvers/mutations/inviteUserToCompany.ts +++ b/back/src/users/resolvers/mutations/inviteUserToCompany.ts @@ -23,9 +23,9 @@ export async function inviteUserToCompanyFn( ): Promise { const email = sanitizeEmail(unsafeEmail); - const existingUser = await prisma.user.findOne({ where: { email } }); + const existingUser = await prisma.user.findUnique({ where: { email } }); - const company = await prisma.company.findOne({ where: { siret } }); + const company = await prisma.company.findUnique({ where: { siret } }); if (existingUser) { // there is already an user with this email diff --git a/back/src/users/resolvers/mutations/login.ts b/back/src/users/resolvers/mutations/login.ts index b7da9800fdf..f5e7f924e8d 100644 --- a/back/src/users/resolvers/mutations/login.ts +++ b/back/src/users/resolvers/mutations/login.ts @@ -15,7 +15,7 @@ const loginResolver: MutationResolvers["login"] = async ( parent, { email, password } ) => { - const user = await prisma.user.findOne({ where: { email: email.trim() } }); + const user = await prisma.user.findUnique({ where: { email: email.trim() } }); if (!user) { throw new UserInputError(`Aucun utilisateur trouvé avec l'email ${email}`, { invalidArgs: ["email"] diff --git a/back/src/users/resolvers/mutations/refuseMembershipRequest.ts b/back/src/users/resolvers/mutations/refuseMembershipRequest.ts index 464c48f54ee..1b54f196c3e 100644 --- a/back/src/users/resolvers/mutations/refuseMembershipRequest.ts +++ b/back/src/users/resolvers/mutations/refuseMembershipRequest.ts @@ -25,7 +25,7 @@ const refuseMembershipRequestResolver: MutationResolvers["refuseMembershipReques const membershipRequest = await getMembershipRequestOrNotFoundError({ id }); const company = await prisma.membershipRequest - .findOne({ where: { id: membershipRequest.id } }) + .findUnique({ where: { id: membershipRequest.id } }) .company(); // check authenticated user is admin of the company @@ -51,11 +51,13 @@ const refuseMembershipRequestResolver: MutationResolvers["refuseMembershipReques // notify requester of refusal const requester = await prisma.membershipRequest - .findOne({ where: { id } }) + .findUnique({ where: { id } }) .user(); await sendMail(userMails.membershipRequestRefused(requester, company)); - const dbCompany = await prisma.company.findOne({ where: { id: company.id } }); + const dbCompany = await prisma.company.findUnique({ + where: { id: company.id } + }); return convertUrls(dbCompany); }; diff --git a/back/src/users/resolvers/mutations/removeUserFromCompany.ts b/back/src/users/resolvers/mutations/removeUserFromCompany.ts index 910dfa1dd10..8526b477b3c 100644 --- a/back/src/users/resolvers/mutations/removeUserFromCompany.ts +++ b/back/src/users/resolvers/mutations/removeUserFromCompany.ts @@ -25,7 +25,7 @@ const removeUserFromCompanyResolver: MutationResolvers["removeUserFromCompany"] await prisma.companyAssociation.delete({ where: { id: companyAssociation.id } }); - const dbCompany = await prisma.company.findOne({ where: { siret } }); + const dbCompany = await prisma.company.findUnique({ where: { siret } }); return convertUrls(dbCompany); }; diff --git a/back/src/users/resolvers/mutations/resetPassword.ts b/back/src/users/resolvers/mutations/resetPassword.ts index 0ee7a0ed3da..63c0adaf2cc 100644 --- a/back/src/users/resolvers/mutations/resetPassword.ts +++ b/back/src/users/resolvers/mutations/resetPassword.ts @@ -8,7 +8,7 @@ const resetPasswordResolver: MutationResolvers["resetPassword"] = async ( parent, { email } ) => { - const user = await prisma.user.findOne({ where: { email } }); + const user = await prisma.user.findUnique({ where: { email } }); if (!user) { throw new Error(`Cet email n'existe pas sur notre plateforme.`); } diff --git a/back/src/users/resolvers/queries/__tests__/apiKey.integration.ts b/back/src/users/resolvers/queries/__tests__/apiKey.integration.ts index 282d2bb024a..14d91351a7e 100644 --- a/back/src/users/resolvers/queries/__tests__/apiKey.integration.ts +++ b/back/src/users/resolvers/queries/__tests__/apiKey.integration.ts @@ -13,7 +13,7 @@ describe("{ query { apiKey } }", () => { const { data } = await query("query { apiKey }"); expect(data.apiKey).toHaveLength(40); // should have created an accessToken in db - const accessToken = await prisma.accessToken.findOne({ + const accessToken = await prisma.accessToken.findUnique({ where: { token: data.apiKey } diff --git a/back/src/users/resolvers/queries/me.ts b/back/src/users/resolvers/queries/me.ts index 309e4311128..0237ac3fd4a 100644 --- a/back/src/users/resolvers/queries/me.ts +++ b/back/src/users/resolvers/queries/me.ts @@ -4,7 +4,7 @@ import { QueryResolvers } from "../../../generated/graphql/types"; const meResolver: QueryResolvers["me"] = async (parent, args, context) => { const me = checkIsAuthenticated(context); - const user = await prisma.user.findOne({ where: { id: me.id } }); + const user = await prisma.user.findUnique({ where: { id: me.id } }); return { ...user, diff --git a/back/src/users/resolvers/queries/membershipRequest.ts b/back/src/users/resolvers/queries/membershipRequest.ts index 5a004e22217..4dacb06f2c3 100644 --- a/back/src/users/resolvers/queries/membershipRequest.ts +++ b/back/src/users/resolvers/queries/membershipRequest.ts @@ -38,11 +38,11 @@ const invitationRequestResolver: QueryResolvers["membershipRequest"] = async ( } const { email } = await prisma.membershipRequest - .findOne({ where: { id: invitationRequest.id } }) + .findUnique({ where: { id: invitationRequest.id } }) .user(); const company = await prisma.membershipRequest - .findOne({ where: { id: invitationRequest.id } }) + .findUnique({ where: { id: invitationRequest.id } }) .company(); // check user is requester or company admin