-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add mongodb and get-refresh-token repositorie
- Loading branch information
1 parent
a3d1ae0
commit ffe9fb3
Showing
8 changed files
with
4,535 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
mongodbMemoryServerOptions: { | ||
instance: { | ||
dbName: "jest", | ||
}, | ||
binary: { | ||
version: "4.0.3", | ||
skipMD5: true, | ||
}, | ||
autoStart: false, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,13 @@ | ||
/* eslint-disable */ | ||
|
||
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */ | ||
module.exports = { | ||
preset: 'ts-jest', | ||
testEnvironment: 'node', | ||
roots: ['<rootDir>/src'], | ||
testEnvironment: "node", | ||
preset: "@shelf/jest-mongodb", | ||
collectCoverageFrom: ['<rootDir>/src/**/*.ts'], | ||
coverageDirectory: 'coverage', | ||
transform: { | ||
".+\\.ts$": "ts-jest", | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { Collection } from "mongodb"; | ||
import { MongoClient } from "mongodb"; | ||
|
||
export const mongoHelper = { | ||
client: null as MongoClient, | ||
async connect(url?: string): Promise<void> { | ||
this.client = await new MongoClient(url || process.env.MONGO_URL).connect(); | ||
}, | ||
|
||
async disconnect(): Promise<void> { | ||
await this.client.close(); | ||
this.client = null; | ||
}, | ||
|
||
dbCollection(): Collection { | ||
return; | ||
}, | ||
|
||
async getCollection(name: string): Promise<Collection> { | ||
try { | ||
return this.client.db().collection(name); | ||
} catch { | ||
await this.connect(); | ||
return this.client.db().collection(name); | ||
} | ||
}, | ||
|
||
// eslint-disable-next-line | ||
map(account: any): any { | ||
const { _id, ...accountWithoudId } = account; | ||
|
||
return { | ||
...accountWithoudId, | ||
id: _id.toString(), | ||
}; | ||
}, | ||
}; |
17 changes: 17 additions & 0 deletions
17
src/infra/db/mongodb/refresh-token-repository/get-refresh-token.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import type { GetRefreshTokenRepository } from "../../../../data/protocols/get-refresh-token-repository"; | ||
import type { AccountModel } from "../../../../domain/models/account"; | ||
import { mongoHelper } from "../helpers/mongo-helper"; | ||
|
||
export class GetRefreshTokenMongoRepository | ||
implements GetRefreshTokenRepository | ||
{ | ||
public async get(refreshToken: string): Promise<AccountModel> { | ||
const accountCollection = await mongoHelper.getCollection("account"); | ||
|
||
const account = await accountCollection.findOne({ | ||
refreshToken, | ||
}); | ||
|
||
return mongoHelper.map(account); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,9 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"declaration": true, | ||
"removeComments": true, | ||
"emitDecoratorMetadata": true, | ||
"experimentalDecorators": true, | ||
"allowSyntheticDefaultImports": true, | ||
"target": "es2017", | ||
"sourceMap": true, | ||
"outDir": "./dist", | ||
"incremental": true, | ||
"skipLibCheck": true, | ||
"strictNullChecks": false, | ||
"noImplicitAny": false, | ||
"strictBindCallApply": false, | ||
"forceConsistentCasingInFileNames": false, | ||
"noFallthroughCasesInSwitch": false | ||
"module": "commonjs", | ||
"target": "es2019", | ||
"esModuleInterop": true, | ||
"allowJs": true | ||
} | ||
} |
Oops, something went wrong.