Skip to content

Commit

Permalink
ci/cd
Browse files Browse the repository at this point in the history
  • Loading branch information
Yash-Ainapure committed Oct 4, 2024
1 parent f9a7a0f commit 275cec6
Show file tree
Hide file tree
Showing 9 changed files with 207 additions and 8 deletions.
44 changes: 44 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: TypeScript Type Check

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
type-check:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: "18"

# Frontend TypeScript check
- name: Install frontend dependencies
run: |
cd frontend
npm ci
- name: TypeScript check (frontend)
run: |
cd frontend
npm run check-build
# Backend TypeScript check
- name: Install backend dependencies
run: |
cd ../backend
npm ci
- name: TypeScript check (backend)
run: |
cd backend
npm run check-build
1 change: 1 addition & 0 deletions backend/dist/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const database_config_1 = require("./config/database.config");
const app = (0, express_1.default)();
app.use(express_1.default.json());
app.use((0, cors_1.default)());
app.use(express_1.default.urlencoded({ extended: true }));
(0, index_1.setupRoutes)(app);
const PORT = env_config_1.config.PORT || 4000;
function startServer() {
Expand Down
6 changes: 3 additions & 3 deletions backend/dist/config/database.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.closeDatabaseConnection = exports.testDatabaseConnection = exports.prisma = void 0;
exports.prisma = void 0;
exports.testDatabaseConnection = testDatabaseConnection;
exports.closeDatabaseConnection = closeDatabaseConnection;
const client_1 = require("@prisma/client");
const adapter_libsql_1 = require("@prisma/adapter-libsql");
const client_2 = require("@libsql/client");
Expand All @@ -33,12 +35,10 @@ function testDatabaseConnection() {
}
});
}
exports.testDatabaseConnection = testDatabaseConnection;
// Function to close the database connection
function closeDatabaseConnection() {
return __awaiter(this, void 0, void 0, function* () {
yield exports.prisma.$disconnect();
console.log("Database connection closed");
});
}
exports.closeDatabaseConnection = closeDatabaseConnection;
3 changes: 3 additions & 0 deletions backend/dist/config/env.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ exports.config = {
PORT: process.env.PORT,
TURSO_DATABASE_URL: process.env.TURSO_DATABASE_URL,
TURSO_AUTH_TOKEN: process.env.TURSO_AUTH_TOKEN,
CLOUD_NAME: process.env.CLOUD_NAME,
API_KEY: process.env.API_KEY,
API_SECRET: process.env.API_SECRET
};
2 changes: 1 addition & 1 deletion backend/dist/controllers/club.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const addClub = (req, res) => __awaiter(void 0, void 0, void 0, function* () {
FoundedDate,
Email,
Password: hashedPassword,
LogoURL,
LogoURL: 'https://img.icons8.com/ios-filled/50/test-account.png',
},
});
res.status(201).json(newClub);
Expand Down
4 changes: 2 additions & 2 deletions backend/dist/middlewares/rateLimiter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", { value: true });
const express_rate_limit_1 = __importDefault(require("express-rate-limit"));
const rateLimiter = (0, express_rate_limit_1.default)({
windowMs: 15 * 60 * 1000,
max: 5,
windowMs: 15 * 60 * 1000, // 15 minutes
max: 5, // Limit each IP to 5 login attempts per windowMs
message: "Too many login attempts, please try again later.",
});
exports.default = rateLimiter;
147 changes: 147 additions & 0 deletions backend/dist/services/cloudnary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.uploadImageToCloudinary = exports.uploads = void 0;
exports.uploadClubLogo = uploadClubLogo;
exports.uploadEventImages = uploadEventImages;
exports.uploadPfp = uploadPfp;
exports.deleteOnCloudinary = deleteOnCloudinary;
const cloudinary_1 = require("cloudinary");
const env_config_1 = require("../config/env.config");
const multer_1 = __importDefault(require("multer"));
const upload = (0, multer_1.default)({ storage: multer_1.default.memoryStorage() });
const fs = __importStar(require("fs"));
cloudinary_1.v2.config({
cloud_name: env_config_1.config.CLOUD_NAME,
api_key: env_config_1.config.API_KEY,
api_secret: env_config_1.config.API_SECRET
});
function uploadPfp(localFilePath) {
return __awaiter(this, void 0, void 0, function* () {
try {
if (!localFilePath)
return null;
const response = yield cloudinary_1.v2.uploader.upload(localFilePath, {
resource_type: "auto",
folder: "profile pictures"
});
fs.unlinkSync(localFilePath);
return {
public_id: response.public_id,
url: response.url,
};
}
catch (error) {
fs.unlinkSync(localFilePath);
return null;
}
});
}
const uploadImageToCloudinary = (file) => {
console.log(file);
return new Promise((resolve, reject) => {
if (!file) {
return reject('No file provided');
}
const uploadStream = cloudinary_1.v2.uploader.upload_stream({ folder: 'club_images' }, (error, result) => {
if (error) {
return reject(error);
}
if (result) {
resolve(result.secure_url); // Returning the secure URL of the uploaded image
}
});
uploadStream.end(file.buffer); // Send file buffer to Cloudinary
});
};
exports.uploadImageToCloudinary = uploadImageToCloudinary;
function uploadClubLogo(file) {
return __awaiter(this, void 0, void 0, function* () {
return new Promise((resolve, reject) => {
cloudinary_1.v2.uploader.upload_stream({ resource_type: 'auto' }, // Automatically determines the resource type
(error, result) => {
if (error) {
reject(error);
}
else {
resolve(result.secure_url); // Return the secure URL of the uploaded file
}
}).end(file.buffer); // Send the file buffer to Cloudinary
});
});
}
function uploadEventImages(localFilePath) {
return __awaiter(this, void 0, void 0, function* () {
try {
if (!localFilePath)
return null;
const response = yield cloudinary_1.v2.uploader.upload(localFilePath, {
resource_type: "auto",
folder: "event images"
});
fs.unlinkSync(localFilePath);
return {
public_id: response.public_id,
url: response.url,
};
}
catch (error) {
fs.unlinkSync(localFilePath);
return null;
}
});
}
function deleteOnCloudinary(public_id) {
return __awaiter(this, void 0, void 0, function* () {
try {
const response = yield cloudinary_1.v2.api.delete_resources([public_id]);
console.log(response);
}
catch (error) {
console.log("Error deleting resource:", error);
}
});
}
const uploads = (file) => {
console.log(file);
return new Promise((resolve) => {
cloudinary_1.v2.uploader.upload(file, { resource_type: "auto" }, (result) => {
resolve({ url: result.url, id: result.public_id });
});
});
};
exports.uploads = uploads;
4 changes: 3 additions & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"scripts": {
"start": "nodemon",
"build": "tsc",
"start:dev": "nodemon"
"start:dev": "nodemon",
"check-types": "tsc --noEmit",
"check-build": "npm run check-types && npm run build"
},
"keywords": [],
"author": "",
Expand Down
4 changes: 3 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
"preview": "vite preview",
"check-types": "tsc --noEmit",
"check-build": "npm run check-types && npm run build"
},
"dependencies": {
"@fortawesome/free-solid-svg-icons": "^6.6.0",
Expand Down

0 comments on commit 275cec6

Please sign in to comment.