Skip to content

Commit

Permalink
fix: save refreshtoken on mongoDb
Browse files Browse the repository at this point in the history
  • Loading branch information
Williancc1557 committed Jul 29, 2022
1 parent 2fc45d9 commit 8f0b42e
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@types/pino-http": "^5.8.1",
"@types/pino-pretty": "^4.7.5",
"@types/supertest": "^2.0.12",
"@types/uuidv4": "^5.0.0",
"@types/validator": "^13.7.4",
"eslint": "^8.20.0",
"git-commit-msg-linter": "^4.1.3",
Expand All @@ -44,6 +45,7 @@
"pino": "^8.3.0",
"pino-http": "^8.1.1",
"pino-pretty": "^8.1.0",
"uuidv4": "^6.2.13",
"validator": "^13.7.0"
}
}
28 changes: 17 additions & 11 deletions src/infra/db/mongodb/account-repository/add-account-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,23 @@ import type { CreateRefreshToken } from "../../../../presentation/protocols/crea
import { mongoHelper } from "../helpers/mongo-helper";

export class AddAccountMongoRepository implements AddAccountRepository {
public constructor(
private readonly createRefreshToken: CreateRefreshToken
) { }
public constructor(private readonly createRefreshToken: CreateRefreshToken) {}

public async add(account: AddAccountInput): Promise<AccountModel> {
const accountCollection = await mongoHelper.getCollection("account");
const { insertedId } = await accountCollection.insertOne(account);
public async add(account: AddAccountInput): Promise<AccountModel> {
const accountCollection = await mongoHelper.getCollection("account");
const { insertedId } = await accountCollection.insertOne(account);

const accountData = await accountCollection.findOne(new ObjectId(insertedId));
const refreshToken = this.createRefreshToken.create((String(accountData._id.id)));
const refreshToken = this.createRefreshToken.create(String(insertedId.id));

return mongoHelper.map(Object.assign(accountData, { refreshToken }));
}
}
await accountCollection.updateOne(
{ _id: new ObjectId(insertedId) },
{ $set: { refreshToken } }
);

const accountData = await accountCollection.findOne(
new ObjectId(insertedId)
);

return mongoHelper.map(accountData);
}
}
20 changes: 20 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,18 @@
resolved "https://registry.yarnpkg.com/@types/tmp/-/tmp-0.2.3.tgz#908bfb113419fd6a42273674c00994d40902c165"
integrity sha512-dDZH/tXzwjutnuk4UacGgFRwV+JSLaXL1ikvidfJprkb7L9Nx1njcRHHmi3Dsvt7pgqqTEeucQuOrWHPFgzVHA==

"@types/[email protected]":
version "8.3.4"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.4.tgz#bd86a43617df0594787d38b735f55c805becf1bc"
integrity sha512-c/I8ZRb51j+pYGAu5CrFMRxqZ2ke4y2grEBO5AUjgSkSk+qT2Ea+OdWElz/OiMf5MNpn2b17kuVBwZLQJXzihw==

"@types/uuidv4@^5.0.0":
version "5.0.0"
resolved "https://registry.yarnpkg.com/@types/uuidv4/-/uuidv4-5.0.0.tgz#2c94e67b0c06d5adb28fb7ced1a1b5f0866ecd50"
integrity sha512-xUrhYSJnkTq9CP79cU3svoKTLPCIbMMnu9Twf/tMpHATYSHCAAeDNeb2a/29YORhk5p4atHhCTMsIBU/tvdh6A==
dependencies:
uuidv4 "*"

"@types/validator@^13.7.4":
version "13.7.4"
resolved "https://registry.yarnpkg.com/@types/validator/-/validator-13.7.4.tgz#33cc949ee87dd47c63e35ba4ad94f6888852be04"
Expand Down Expand Up @@ -5089,6 +5101,14 @@ [email protected], uuid@^8.3.1:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-8.3.2.tgz#80d5b5ced271bb9af6c445f21a1a04c606cefbe2"
integrity sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==

uuidv4@*, uuidv4@^6.2.13:
version "6.2.13"
resolved "https://registry.yarnpkg.com/uuidv4/-/uuidv4-6.2.13.tgz#8f95ec5ef22d1f92c8e5d4c70b735d1c89572cb7"
integrity sha512-AXyzMjazYB3ovL3q051VLH06Ixj//Knx7QnUSi1T//Ie3io6CpsPu9nVMOx5MoLWh6xV0B9J0hIaxungxXUbPQ==
dependencies:
"@types/uuid" "8.3.4"
uuid "8.3.2"

v8-compile-cache-lib@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf"
Expand Down

0 comments on commit 8f0b42e

Please sign in to comment.