Skip to content

Commit

Permalink
Merge branch 'bamiwo-API-Doc' of https://github.com/bammietop03/hng_b…
Browse files Browse the repository at this point in the history
…oilerplate_expressjs into bamiwo-API-Doc
  • Loading branch information
bammietop03 committed Jul 24, 2024
2 parents 189617f + 673b573 commit 7c35be5
Show file tree
Hide file tree
Showing 30 changed files with 1,249 additions and 463 deletions.
8 changes: 7 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ GOOGLE_CLIENT_SECRET=
#Redis Configuration
REDIS_HOST=
REDIS_PORT=
GOOGLE_AUTH_CALLBACK_URL=

# Cloudinary setup
CLOUDINARY_CLOUD_NAME=
CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=
=======
GOOGLE_AUTH_CALLBACK_URL=
7 changes: 3 additions & 4 deletions contributors.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

[Nainah23](https://github.com/Nainah23)
Erasmus Tayviah (StarmannRassy)

- [Nainah23](https://github.com/Nainah23)
- Erasmus Tayviah (StarmannRassy)
- [Adekolu Samuel Samixx](https://github.com/samixYasuke)
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@types/express": "^4.17.21",
"@types/fs-extra": "^11.0.4",
"@types/jest": "^29.5.12",
"@types/multer": "^1",
"@types/node": "^16.18.103",
"@types/passport": "^1.0.16",
"@types/supertest": "^6.0.2",
Expand Down Expand Up @@ -59,6 +60,7 @@
"bcryptjs": "^2.4.3",
"bull": "^4.15.1",
"class-validator": "^0.14.1",
"cloudinary": "^2.3.0",
"config": "^3.3.12",
"cors": "^2.8.5",
"dayjs": "^1.11.12",
Expand All @@ -68,13 +70,12 @@
"express-validator": "^7.1.0",
"fs-extra": "^11.2.0",
"handlebars": "^4.7.8",

"jest-mock-extended": "^3.0.7",

"jest": "^29.7.0",
"json2csv": "^6.0.0-alpha.2",

"jsonwebtoken": "^9.0.2",
"multer": "^1.4.5-lts.1",
"multer-storage-cloudinary": "^4.0.0",
"node-mailer": "^0.1.1",
"pdfkit": "^0.15.0",
"passport": "^0.7.0",
Expand All @@ -88,6 +89,7 @@
"ts-node-dev": "^2.0.0",
"twilio": "^5.2.2",
"typeorm": "^0.3.20",
"uuid": "^10.0.0",
"zod": "^3.23.8"
},
"lint-staged": {
Expand Down
16 changes: 16 additions & 0 deletions src/config/cloudinary.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import * as cloudinary from "cloudinary";
import { ConfigOptions } from "cloudinary";

const cloudinaryConfig = (
cloudName: string,
apiKey: string,
apiSecret: string,
): ConfigOptions => {
return cloudinary.v2.config({
cloud_name: cloudName,
api_key: apiKey,
api_secret: apiSecret,
});
};

export default cloudinaryConfig;
43 changes: 27 additions & 16 deletions src/config/google.passport.config.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
import config from ".";
import passport from "passport";
import { Strategy as GoogleStrategy, Profile, VerifyCallback } from "passport-google-oauth2";
import {
Strategy as GoogleStrategy,
Profile,
VerifyCallback,
} from "passport-google-oauth2";

passport.use(new GoogleStrategy({
clientID: config.GOOGLE_CLIENT_ID,
clientSecret: config.GOOGLE_CLIENT_SECRET,
callbackURL: config.GOOGLE_AUTH_CALLBACK_URL
},
async (_accessToken: string, _refreshToken: string, profile: Profile, done: VerifyCallback) => {
try {
return done(null, profile);
} catch (error) {
return done(error);
}
}
));
passport.use(
new GoogleStrategy(
{
clientID: config.GOOGLE_CLIENT_ID,
clientSecret: config.GOOGLE_CLIENT_SECRET,
callbackURL: config.GOOGLE_AUTH_CALLBACK_URL,
},
async (
_accessToken: string,
_refreshToken: string,
profile: Profile,
done: VerifyCallback,
) => {
try {
return done(null, profile);
} catch (error) {
return done(error);
}
},
),
);


export default passport;
export default passport;
6 changes: 3 additions & 3 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const config = {
TWILIO_SID: process.env.TWILIO_SID,
TWILIO_AUTH_TOKEN: process.env.TWILIO_AUTH_TOKEN,
TWILIO_PHONE_NUMBER: process.env.TWILIO_PHONE_NUMBER,
GOOGLE_CLIENT_ID:process.env.GOOGLE_CLIENT_ID,
GOOGLE_CLIENT_SECRET:process.env.GOOGLE_CLIENT_SECRET,
GOOGLE_AUTH_CALLBACK_URL: process.env.GOOGLE_AUTH_CALLBACK_URL
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET,
GOOGLE_AUTH_CALLBACK_URL: process.env.GOOGLE_AUTH_CALLBACK_URL,
};

export default config;
47 changes: 47 additions & 0 deletions src/config/multer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import multer from "multer";
import { v2 as cloudinary } from "cloudinary";
import { CloudinaryStorage } from "multer-storage-cloudinary";
import cloudinaryConfig from "./cloudinary";
import * as dotenv from "dotenv";
dotenv.config();

interface CustomParams {
folder: string;
allowedFormats: string[];
}

const cloudinaryConfigOptions = cloudinaryConfig(
process.env["CLOUDINARY_CLOUD_NAME"] as string,
process.env["CLOUDINARY_API_KEY"] as string,
process.env["CLOUDINARY_API_SECRET"] as string,
);

cloudinary.config(cloudinaryConfigOptions);

const storage = new CloudinaryStorage({
cloudinary,
params: {
folder: "images",
allowedFormats: ["jpg", "png", "jpeg"],
} as CustomParams,
});

const FILE_SIZE = 1024 * 1024 * 2; // 2MB

export const multerConfig = multer({
storage,
limits: {
fileSize: FILE_SIZE,
},
fileFilter: (_req, file, cb) => {
if (!file.mimetype.startsWith("image/")) {
return cb(new Error("Only images are allowed"));
}
if (file.size > FILE_SIZE) {
return cb(new Error("Image should not be more than 4MB"));
}
cb(null, true);
},
});

export { cloudinary };
Loading

0 comments on commit 7c35be5

Please sign in to comment.