Skip to content

Commit

Permalink
Update to Prisma 2.13
Browse files Browse the repository at this point in the history
  • Loading branch information
Riron committed Dec 8, 2020
1 parent 75addc0 commit 551e4cf
Show file tree
Hide file tree
Showing 114 changed files with 438 additions and 369 deletions.
30 changes: 15 additions & 15 deletions back/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions back/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions back/src/__tests__/auth.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand All @@ -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();
});
});
6 changes: 3 additions & 3 deletions back/src/__tests__/factories.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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);
});
21 changes: 10 additions & 11 deletions back/src/__tests__/factories.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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<UserCreateInput> = {}) => {
export const userFactory = async (
opt: Partial<Prisma.UserCreateInput> = {}
) => {
const defaultPassword = await hash("pass", 10);
const userIndex = (await prisma.user.count()) + 1;
const data = {
Expand Down Expand Up @@ -54,7 +53,7 @@ function siretify(index) {
* @param opt: extram parameters
*/
export const companyFactory = async (
companyOpts: Partial<CompanyCreateInput> = {}
companyOpts: Partial<Prisma.CompanyCreateInput> = {}
) => {
const opts = companyOpts || {};
const companyIndex = (await prisma.company.count()) + 1;
Expand All @@ -77,7 +76,7 @@ export const companyFactory = async (
*/
export const userWithCompanyFactory = async (
role,
companyOpts: Partial<CompanyCreateInput> = {}
companyOpts: Partial<Prisma.CompanyCreateInput> = {}
) => {
const company = await companyFactory(companyOpts);

Expand Down Expand Up @@ -184,7 +183,7 @@ const formdata = {
recipientCompanyName: "WASTE COMPANY"
};

export const tempStorageData: TemporaryStorageDetailCreateInput = {
export const tempStorageData: Prisma.TemporaryStorageDetailCreateInput = {
tempStorerQuantityType: "ESTIMATED",
tempStorerQuantityReceived: 1,
tempStorerWasteAcceptationStatus: "ACCEPTED",
Expand Down Expand Up @@ -248,7 +247,7 @@ export const formFactory = async ({
opt = {}
}: {
ownerId: string;
opt?: Partial<FormCreateInput>;
opt?: Partial<Prisma.FormCreateInput>;
}) => {
const formParams = { ...formdata, ...opt };
return prisma.form.create({
Expand All @@ -265,7 +264,7 @@ export const formWithTempStorageFactory = async ({
opt = {}
}: {
ownerId: string;
opt?: Partial<FormCreateInput>;
opt?: Partial<Prisma.FormCreateInput>;
}) => {
return formFactory({
ownerId,
Expand Down
12 changes: 6 additions & 6 deletions back/src/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
});

Expand Down Expand Up @@ -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));
});
Expand All @@ -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) {
Expand Down Expand Up @@ -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 }
});
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions back/src/common/middlewares/graphqlBodyParser.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Request, Response, NextFunction } from "express";
import bodyParser from "body-parser";
import { text } from "body-parser";

/**
* GraphQL server middleware to support application/graphql requests
* Taken from https://github.com/graphql-middleware/body-parser-graphql
*/
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
Expand Down
16 changes: 7 additions & 9 deletions back/src/companies/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

import prisma from "src/prisma";
import {
CompanyWhereUniqueInput,
User,
TraderReceiptWhereUniqueInput,
TransporterReceiptWhereUniqueInput,
Prisma,
Company,
TraderReceipt,
TransporterReceipt
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
}
Expand All @@ -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();
}
Expand Down
4 changes: 2 additions & 2 deletions back/src/companies/resolvers/CompanyFavorite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions back/src/companies/resolvers/CompanyPrivate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions back/src/companies/resolvers/CompanyPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions back/src/companies/resolvers/CompanySearchResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading

0 comments on commit 551e4cf

Please sign in to comment.