Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #36

Closed
wants to merge 179 commits into from
Closed

Dev #36

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
179 commits
Select commit Hold shift + click to select a range
058b075
Creat the types
SarahAbuirmeileh Oct 2, 2023
406c2f9
Edit the exiteing types and addind aditional attributes
SarahAbuirmeileh Oct 2, 2023
9a16488
add entities
Oct 3, 2023
3b73a7c
Merge pull request #1 from SarahAbuirmeileh/db
TarteelTamimi Oct 3, 2023
8c51b59
edit the types, the id become a number
SarahAbuirmeileh Oct 3, 2023
035dea5
last editing for types
SarahAbuirmeileh Oct 3, 2023
d7cf6b7
Merge pull request #2 from SarahAbuirmeileh/edit-types
SarahAbuirmeileh Oct 3, 2023
1a39743
edit some sttributes and entity
SarahAbuirmeileh Oct 3, 2023
af570f5
Merge pull request #3 from SarahAbuirmeileh/edit-entities
SarahAbuirmeileh Oct 3, 2023
95bc810
add capacity attribute for v.w
SarahAbuirmeileh Oct 3, 2023
f809682
Merge pull request #4 from SarahAbuirmeileh/add-capacity
SarahAbuirmeileh Oct 3, 2023
be74038
Creat a createPermission function
SarahAbuirmeileh Oct 3, 2023
3073fd7
creat simple router to test creatPermission
SarahAbuirmeileh Oct 3, 2023
610f15c
creat a function to delete a permission
SarahAbuirmeileh Oct 3, 2023
13479b3
creat delete permission end point
SarahAbuirmeileh Oct 3, 2023
0ba44c8
edit res.locals
SarahAbuirmeileh Oct 3, 2023
91fb30b
creat a function to edit the name of permission
SarahAbuirmeileh Oct 3, 2023
303799e
creat getSender function
SarahAbuirmeileh Oct 3, 2023
537b335
creat edit permission end point
SarahAbuirmeileh Oct 3, 2023
827068e
creat get permission and get permissions functions
SarahAbuirmeileh Oct 3, 2023
1bf6ca1
creat 2 end point to get user by id and all users
SarahAbuirmeileh Oct 3, 2023
f648b2b
remove the sender
SarahAbuirmeileh Oct 3, 2023
4c2cd45
Merge pull request #5 from SarahAbuirmeileh/permission-coroller
SarahAbuirmeileh Oct 3, 2023
2842874
creat all role controller functions
SarahAbuirmeileh Oct 3, 2023
e5c42d4
creat a router for role end points
SarahAbuirmeileh Oct 3, 2023
54a5c28
Merge pull request #6 from SarahAbuirmeileh/role-controller
SarahAbuirmeileh Oct 3, 2023
f464abc
Creat get, edit, creat, delete, get all v.w functions
SarahAbuirmeileh Oct 3, 2023
e727033
creat the router for v.w
SarahAbuirmeileh Oct 3, 2023
c7e62cf
Merge pull request #7 from SarahAbuirmeileh/volunteryWork-controller
SarahAbuirmeileh Oct 3, 2023
76a6ab8
edit get permission to get by name , id and all permissions
SarahAbuirmeileh Oct 3, 2023
64b9224
edit get roles to bring according to id , name and al of them
SarahAbuirmeileh Oct 3, 2023
cbcabdd
creat advanced search for voluntary work
SarahAbuirmeileh Oct 3, 2023
5955887
add capacity
SarahAbuirmeileh Oct 3, 2023
eaea9e2
edit the types of dates to be string
SarahAbuirmeileh Oct 3, 2023
c96e0f5
adding started and finished date to adances search
SarahAbuirmeileh Oct 3, 2023
26af106
Merge pull request #8 from SarahAbuirmeileh/analytic-functions
SarahAbuirmeileh Oct 3, 2023
ce779fc
edit the voluntary work type
SarahAbuirmeileh Oct 4, 2023
f6acfd2
added search by started and finished date
SarahAbuirmeileh Oct 4, 2023
0be8b4f
add org. admin & org. profile controllers
Oct 4, 2023
4f13090
add routers for org. admin & org. profile
Oct 4, 2023
346d9c1
Edit the entites and v.w types and creat v.w to match the started and…
SarahAbuirmeileh Oct 5, 2023
9902f0b
Edit the creat v.w and edit v.w functions
SarahAbuirmeileh Oct 5, 2023
66e2c1d
edit v.w rout and controller
SarahAbuirmeileh Oct 5, 2023
b5de950
add started and finished before and after date to advanced search
SarahAbuirmeileh Oct 5, 2023
2acd7d9
creat rating more or less to advanced search
SarahAbuirmeileh Oct 5, 2023
44a10c6
edit the put end points to send the id in the params
SarahAbuirmeileh Oct 5, 2023
e7089a8
creat put rating function
SarahAbuirmeileh Oct 5, 2023
1691665
creat add feedback function
SarahAbuirmeileh Oct 5, 2023
dcf6a5b
creat a function to add images to data base by url
SarahAbuirmeileh Oct 5, 2023
107bfe9
Merge pull request #9 from SarahAbuirmeileh/advanced-search
SarahAbuirmeileh Oct 5, 2023
959d066
creat valodator for role and permission
SarahAbuirmeileh Oct 5, 2023
02b8ac4
Creat validation for organizationAdmin
SarahAbuirmeileh Oct 5, 2023
ae01d88
Creat organization Profile validation
SarahAbuirmeileh Oct 5, 2023
0ea1087
Creat skill tag validation
SarahAbuirmeileh Oct 5, 2023
bf9f1ef
Creat validation for vulontary work and the date
SarahAbuirmeileh Oct 5, 2023
a2091ac
Creat a validation for vulonteer
SarahAbuirmeileh Oct 5, 2023
c01f55d
Merge pull request #10 from SarahAbuirmeileh/validation
SarahAbuirmeileh Oct 5, 2023
5595908
Creat a login controller to creat a token for valid users
SarahAbuirmeileh Oct 6, 2023
d9b4d9a
test
Oct 6, 2023
fdcebb3
Merge pull request #11 from SarahAbuirmeileh/tarteelControllers
TarteelTamimi Oct 6, 2023
16e1713
Creat authorization
SarahAbuirmeileh Oct 6, 2023
39d2ecc
Creat the authentication
SarahAbuirmeileh Oct 6, 2023
a8102f7
creat the cookies and save the token in the cookie
SarahAbuirmeileh Oct 6, 2023
589148a
Merge branch 'dev' into auth
SarahAbuirmeileh Oct 6, 2023
e116d1d
Merge pull request #12 from SarahAbuirmeileh/auth
SarahAbuirmeileh Oct 6, 2023
5a25e8a
Dreat and edit the whole route with validation, authorization and au…
SarahAbuirmeileh Oct 6, 2023
4d4d0db
Creat new auth to prevent volnteer, v.w, orgProfile and orgAdmin to b…
SarahAbuirmeileh Oct 6, 2023
0678d69
Creat check participation function to allow rating and give feedback …
SarahAbuirmeileh Oct 6, 2023
9e3bbc7
set up the units of testing
Oct 6, 2023
6ad0e2a
Merge pull request #13 from SarahAbuirmeileh/unitTesting
TarteelTamimi Oct 6, 2023
cfcf88b
added new attribute to calculate the number of volunteer which partic…
SarahAbuirmeileh Oct 6, 2023
69a7c46
Merge pull request #14 from SarahAbuirmeileh/routs
SarahAbuirmeileh Oct 6, 2023
f38fd05
Creat functions to register in voluntary work by volunteer and by adm…
SarahAbuirmeileh Oct 6, 2023
7032c88
Merge pull request #15 from SarahAbuirmeileh/edit-controllers
SarahAbuirmeileh Oct 6, 2023
d4289f4
volunteer controller
Oct 6, 2023
4a966e5
Merge pull request #16 from SarahAbuirmeileh/volunteerController
TarteelTamimi Oct 6, 2023
7913488
edit creat volunteer and add the controllers to routes
SarahAbuirmeileh Oct 6, 2023
2eb15db
Creat get volunteers function and router
SarahAbuirmeileh Oct 6, 2023
2c9d85b
Merge pull request #17 from SarahAbuirmeileh/volunteer-controller
SarahAbuirmeileh Oct 6, 2023
5d72857
Edit orgAdmin to change the password if the old password is correct
SarahAbuirmeileh Oct 7, 2023
2510f0f
Creat get orgProfile by admin name
SarahAbuirmeileh Oct 7, 2023
b0836dc
Creat derigtration function for voluntary work
SarahAbuirmeileh Oct 7, 2023
393bda5
Add validation if edited in the put method
SarahAbuirmeileh Oct 7, 2023
471d59d
Adding validation of id on put methood
SarahAbuirmeileh Oct 7, 2023
8c5a0dc
Add DOF attribute for volunteer and orgAdmin and make the volunter ty…
SarahAbuirmeileh Oct 7, 2023
b773c0d
allow nolnteer to edit password if the old password is correct
SarahAbuirmeileh Oct 7, 2023
8026bc9
Merge pull request #18 from SarahAbuirmeileh/project-testing
SarahAbuirmeileh Oct 7, 2023
ac1743b
Creat s3 configration and upload images to s3 bucket
SarahAbuirmeileh Oct 7, 2023
c377b8b
Merge pull request #19 from SarahAbuirmeileh/s3
SarahAbuirmeileh Oct 7, 2023
def8a94
complete error handling
Oct 7, 2023
9f7bb18
solve the conflict
Oct 7, 2023
2fc1c84
Merge branch 'dev' into errorHandling
TarteelTamimi Oct 7, 2023
57e2eed
Merge pull request #20 from SarahAbuirmeileh/errorHandling
TarteelTamimi Oct 7, 2023
2c020e9
Edit the cookies and error handler
SarahAbuirmeileh Oct 8, 2023
10b0eec
Edit creat volunteer so the normal user can only creat volunteer, whi…
SarahAbuirmeileh Oct 8, 2023
e716284
Assigne a role to vilunteer when creating
SarahAbuirmeileh Oct 8, 2023
cb38814
Edit the returned attribute for volunteer and the atrributes for rela…
SarahAbuirmeileh Oct 8, 2023
607b7f1
Edit the authorization for all endpoins
SarahAbuirmeileh Oct 8, 2023
30d5a3c
edit delete and get orgProfile
SarahAbuirmeileh Oct 8, 2023
0c202a8
Edit creat admin so when creat it assgin a role to him
SarahAbuirmeileh Oct 8, 2023
9708656
Edit the get admin so return it without id and password
SarahAbuirmeileh Oct 8, 2023
149e064
Edit the authorization middlewares
SarahAbuirmeileh Oct 8, 2023
a8a153a
edit get voluntary works function to make the relation AND and to bri…
SarahAbuirmeileh Oct 8, 2023
1a50c88
Edit get volunteers to need attributes with subrelations
SarahAbuirmeileh Oct 8, 2023
eb06231
edit registration in vw
SarahAbuirmeileh Oct 8, 2023
dbaa9d6
edit the deregistration function
SarahAbuirmeileh Oct 8, 2023
ed9dad0
edit put reating fun and validation
SarahAbuirmeileh Oct 8, 2023
4e70873
edit s3
SarahAbuirmeileh Oct 8, 2023
4367a5d
Adding the id validation middleware for all routes
SarahAbuirmeileh Oct 8, 2023
3e0ab8f
Merge pull request #21 from SarahAbuirmeileh/project-testing
SarahAbuirmeileh Oct 8, 2023
c63d6a7
add logs and logger
Oct 8, 2023
6a27ab2
Merge branch 'dev' into logs
TarteelTamimi Oct 8, 2023
4ad3318
Merge pull request #22 from SarahAbuirmeileh/logs
TarteelTamimi Oct 8, 2023
5601e93
complete logs & logger
Oct 8, 2023
4bc6fa2
Merge pull request #23 from SarahAbuirmeileh/logs
TarteelTamimi Oct 8, 2023
ffa8a5c
Use the Log nameSpace, and edit the logger data in orgAdmin to be sur…
SarahAbuirmeileh Oct 9, 2023
9ee37c0
Edit the logger call in orgProfile
SarahAbuirmeileh Oct 9, 2023
b27bcee
Edit to add premium to logger type
SarahAbuirmeileh Oct 9, 2023
b0ecd1e
Edit permission logger call
SarahAbuirmeileh Oct 9, 2023
d9dc5f7
Edit role logger call
SarahAbuirmeileh Oct 9, 2023
97108ab
Edit voluntary work logger calls
SarahAbuirmeileh Oct 9, 2023
c899921
Edit volunteer logger calls
SarahAbuirmeileh Oct 9, 2023
b057e8a
Adding extra information with specific details about the loging process
SarahAbuirmeileh Oct 9, 2023
e82eca3
Merge pull request #24 from SarahAbuirmeileh/check-logger
SarahAbuirmeileh Oct 9, 2023
1e63faa
Adding loging to failed authurization
SarahAbuirmeileh Oct 9, 2023
e20df5d
Adding logging for failed authunication
SarahAbuirmeileh Oct 9, 2023
701df43
Creat logger for failed validation
SarahAbuirmeileh Oct 9, 2023
bec7ae5
auth edit
SarahAbuirmeileh Oct 9, 2023
af850dd
Merge pull request #25 from SarahAbuirmeileh/more-logs
SarahAbuirmeileh Oct 9, 2023
6182bcf
Adding the system error logger
SarahAbuirmeileh Oct 9, 2023
90bc67b
Merge pull request #26 from SarahAbuirmeileh/logger
SarahAbuirmeileh Oct 9, 2023
74b5b65
Creat the basics for docker
SarahAbuirmeileh Oct 10, 2023
e12b6e5
use mysql2
khaledez Oct 10, 2023
d2eb382
Adding docker compose file for production
SarahAbuirmeileh Oct 10, 2023
587900b
Adding the github actions to deploy the app
SarahAbuirmeileh Oct 10, 2023
e2dc053
Merge pull request #27 from SarahAbuirmeileh/docker
SarahAbuirmeileh Oct 10, 2023
481fd31
Edit name for log in registry
SarahAbuirmeileh Oct 10, 2023
f6a845d
Delete the health checks
SarahAbuirmeileh Oct 10, 2023
11a7ec1
Edit the iamge name
SarahAbuirmeileh Oct 10, 2023
3095ad8
Edit db_name
SarahAbuirmeileh Oct 10, 2023
d541a83
Adding the script for instnces
SarahAbuirmeileh Oct 10, 2023
64d3b92
Adding the AWS CloudWatch configration
SarahAbuirmeileh Oct 10, 2023
6e16ecb
Creat AWS Cloud Watch controller
SarahAbuirmeileh Oct 10, 2023
a3fcd3f
Creat migration files
SarahAbuirmeileh Oct 10, 2023
158fd3c
Solve ERR_UNKNOWN_FILE_EXTENSION error
WaleedJubeh Oct 10, 2023
7a02876
Edit the megrations and add them to docker and git hub actions
SarahAbuirmeileh Oct 11, 2023
dd7b867
Test megration with github actions
SarahAbuirmeileh Oct 11, 2023
a9341fe
megration testing
SarahAbuirmeileh Oct 11, 2023
a843086
Adding env var
SarahAbuirmeileh Oct 11, 2023
c0d9553
Preparing the migrations
SarahAbuirmeileh Oct 11, 2023
37dd377
Calling loging to aws-cloudWatch in org admin rout
SarahAbuirmeileh Oct 11, 2023
2278e16
Call the loggers by .then .catch
SarahAbuirmeileh Oct 11, 2023
9ba321d
Calling loging to aws-cloudWatch in org profile rout
SarahAbuirmeileh Oct 11, 2023
7d10918
Calling loging to aws-cloudWatch in permission rout
SarahAbuirmeileh Oct 11, 2023
ffa99a8
Calling loging to aws-cloudWatch in role rout
SarahAbuirmeileh Oct 11, 2023
94a4ee3
Calling loging to aws-cloudWatch in voluntary work rout
SarahAbuirmeileh Oct 11, 2023
fecc3c5
Calling loging to aws-cloudWatch in volunteer rout
SarahAbuirmeileh Oct 11, 2023
7e9cf26
Merge pull request #30 from SarahAbuirmeileh/aws-cloud-watch
SarahAbuirmeileh Oct 11, 2023
ec51503
Merge pull request #31 from SarahAbuirmeileh/megrations
SarahAbuirmeileh Oct 11, 2023
1a958eb
test
Oct 15, 2023
833b980
optimize error handler
Oct 15, 2023
1cfc72b
Merge pull request #32 from SarahAbuirmeileh/errorHandler
TarteelTamimi Oct 15, 2023
26e273a
Edit logs and login controller and test AWS cloud Watch
SarahAbuirmeileh Oct 15, 2023
6e943a0
Adding instance ip
SarahAbuirmeileh Oct 15, 2023
740a3bc
edit id
SarahAbuirmeileh Oct 15, 2023
3df1223
يا رب يزبط
SarahAbuirmeileh Oct 15, 2023
91136eb
Update ec2 instance
SarahAbuirmeileh Oct 17, 2023
2e229df
Update build.yml
SarahAbuirmeileh Oct 17, 2023
09057f8
Update dataSource.ts
SarahAbuirmeileh Oct 17, 2023
489b032
Update build.yml
SarahAbuirmeileh Oct 17, 2023
f9b2ad6
Update build.yml
SarahAbuirmeileh Oct 18, 2023
c4486ae
Update build.yml
SarahAbuirmeileh Oct 18, 2023
90a8222
Update build.yml
SarahAbuirmeileh Oct 18, 2023
32c927f
Update build.yml
SarahAbuirmeileh Oct 18, 2023
26a8b12
Update build.yml
SarahAbuirmeileh Oct 18, 2023
5bb9832
Update build.yml
SarahAbuirmeileh Oct 18, 2023
1e04595
Update docker-compose-prod.yml
SarahAbuirmeileh Oct 18, 2023
eacd012
Update build.yml
SarahAbuirmeileh Oct 18, 2023
42ca035
Update build.yml
SarahAbuirmeileh Oct 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": [
"@babel/preset-env"
]
}
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
.env
84 changes: 84 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: Docker Image CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:

build:

runs-on: ubuntu-latest

permissions:
contents: read
packages: write


steps:
- uses: actions/checkout@v3

- name: Set image version (tag)
id: image_version
run: echo "gitsha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: login to Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: sarahabuirmeileh
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build the Docker image
run: docker build . --file Dockerfile --tag ghcr.io/sarahabuirmeileh/serve-and-shine:${{ steps.image_version.outputs.gitsha }}
- name: Puplish docker image
run: docker push ghcr.io/sarahabuirmeileh/serve-and-shine:${{ steps.image_version.outputs.gitsha }}
- name: configer docker host
uses: khaledez/configure-docker-host@v1
with:
host: 13.43.121.108
user: github
ssh-private-key: ${{ secrets.DEPLOYMENT_KEY }}

- name: deploy
run: docker compose -f docker-compose-prod.yml up -d
env:
DB_PASSWORD: ${{ secrets.DB_PASSWORD}}
GIT_VERSISON: ${{steps.image_version.outputs.gitsha}}
SECRET_KEY: ${{ secrets.SECRET_KEY}}
DB_HOST: ${{ secrets.DB_HOST}}
DB_PORT: ${{ secrets.DB_PORT}}
DB_USERNAME: ${{ secrets.DB_USERNAME}}
DB_NAME: ${{ secrets.DB_NAME}}
AWS_BUCKET_NAME: ${{ secrets.AWS_BUCKET_NAME}}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID}}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY}}
AWS_REGION: ${{ secrets.AWS_REGION}}
AWS_CERTIFICATES_BUCKET_NAME: ${{ secrets.AWS_CERTIFICATES_BUCKET_NAME}}
PORT: ${{ secrets.PORT}}

- name: print logs
if: always()
run: docker compose logs

- name: Run Migrations
run: |
docker compose -f docker-compose-prod.yml exec app npx typeorm-ts-node-esm migration:run -d ./src/db/dataSource.ts &&
docker compose -f docker-compose-prod.yml exec app mv ./src/db/migrations/1697005494066-CreateRoles.ts ./src/db/migration &&
docker compose -f docker-compose-prod.yml exec app npx typeorm-ts-node-esm migration:run -d ./src/db/dataSource.ts &&
docker compose -f docker-compose-prod.yml exec app mv ./src/db/migrations/1697005554406-RootUser.ts ./src/db/migration &&
docker compose -f docker-compose-prod.yml exec app npx typeorm-ts-node-esm migration:run -d ./src/db/dataSource.ts
env:
DB_PASSWORD: ${{ secrets.DB_PASSWORD}}
DB_HOST: ${{ secrets.DB_HOST}}
DB_PORT: ${{ secrets.DB_PORT}}
DB_USERNAME: ${{ secrets.DB_USERNAME}}
DB_NAME: ${{ secrets.DB_NAME}}
GIT_VERSISON: ${{steps.image_version.outputs.gitsha}}
PORT: ${{ secrets.PORT}}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID}}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY}}



4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules
dist
.env
.env
.env.test
logger
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"cSpell.words": [
"Deregistration"
]
}
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:20-alpine

WORKDIR /user/app
COPY package.json package-lock.json ./

RUN npm ci

RUN apk add curl

ADD . .
RUN npm run build

HEALTHCHECK --interval=10s --timeout=3s \
CMD curl -f http://localhost/ || exit 1

CMD node --loader ts-node/esm ./dist/app.js
28 changes: 28 additions & 0 deletions __test__/createOrgAdmin.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import dataSource, { initDB } from '../dist/src/db/dataSource.js'
import { creatOrganizationAdmin } from '../dist/src/controllers/organizationAdmin.js';

beforeAll(async () => {
await initDB();
});

afterAll(async () => {
await dataSource.destroy();
});

const tmpData = {
"name": "Sarah Abu Irmaileh",
"email": "tamimitarteel27@gamil.com",
"password": "123456",
"organizationId": "e4b41a72-2abe-459c-8657-7a09956f1243"
};

describe("create an organization admin", () => {
let data;
beforeAll(async () => {
data = await creatOrganizationAdmin({name: tmpData.name, email: tmpData.email, password: tmpData.password, organizationId: tmpData.organizationId});
})

it("returns a success response", async () => {
expect(data.name).toBe('Sarah Abu Irmaileh');
})
})
41 changes: 21 additions & 20 deletions app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,48 @@ import "./config.js"
import express from 'express'
import dotenv from 'dotenv'
import createError from 'http-errors'
import dataSource from './src/db/dataSource.js'
import { initDB } from './src/db/dataSource.js'
import logger from 'morgan'
import cookieParser from 'cookie-parser'
import fileUpload from 'express-fileupload';

import indexRouter from "./src/routes/index.js"
import permissionRouter from "./src/routes/permission.js"
import roleRouter from "./src/routes/role.js"
import voluntaryWorkRouter from "./src/routes/voluntaryWork.js"
import organizationAdminRouter from "./src/routes/organizationAdmin.js"
import organizationProfileRouter from "./src/routes/organizationProfile.js"
import volunteerRouter from "./src/routes/volunteer.js"
import { authenticate } from "./src/middleware/auth/authenticate.js"
import { errorHandler } from "./src/middleware/errorHandler/errorHandler.js"

const app = express();
dotenv.config();
const PORT = process.env.PORT || 3000;

app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(fileUpload({ limits: { fileSize: 50 * 1024 * 1024 } }))

app.use('/', indexRouter);
// app.use('/users', usersRouter);
app.use('/permission', authenticate, permissionRouter);
app.use('/role', authenticate, roleRouter);
app.use('/voluntaryWork', authenticate, voluntaryWorkRouter);
app.use('/organizationAdmin', /*authenticate,*/ organizationAdminRouter);
app.use('/organizationProfile', /*authenticate,*/ organizationProfileRouter);
app.use("/volunteer", volunteerRouter);

// catch 404 and forward to error handler
app.use(function (req, res, next) {
next(createError(404));
});


// error handler
app.use(function (err: any, req: any, res: any, next: any) {
// set locals, only providing error in development
res.locals.message = err.message;
res.locals.error = req.app.get('env') === 'development' ? err : {};

// render the error page
res.status(err.status || 500).send({ error: err.message });
});

dataSource.initialize().then(() => {
console.log("Connected to DB!");
}).catch(err => {
console.error('Failed to connect to DB: ' + err);
});
app.use(errorHandler);

app.listen(PORT, () => {
logger(`App is listening on port ${PORT}`);
console.log(`App is listening on port ${PORT} and host http://localhost:${PORT}`);
initDB();
});


export default app;
36 changes: 36 additions & 0 deletions docker-compose-prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: '3'

services:
mysql:
image: mysql
environment:
- MYSQL_ROOT_PASSWORD=$DB_PASSWORD
- MYSQL_DATABASE=$DB_NAME
volumes:
- db-data:/var/lib/mysql
ports:
- "3306:3306"
healthcheck:
test: [ "CMD", "mysqladmin", "ping", "-h", "localhost" ]
timeout: 20s
retries: 10
restart: always

app:
image: ghcr.io/sarahabuirmeileh/serve-and-shine:$GIT_VERSISON
mem_limit: 5g
restart: always #like sysd service
environment:
- PORT=80
- DB_HOST=mysql # to comunicate the servies in the same project ny the name of the serevice
- DB_USERNAME=$DB_USERNAME
- DB_PASSWORD=$DB_PASSWORD
- DB_NAME=$DB_NAME
ports:
- "80:80"
depends_on:
mysql:
condition: service_healthy

volumes:
db-data:
35 changes: 35 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
version: "3"

services:
mysql:
container_name: db
image: mysql
environment:
- MYSQL_ROOT_PASSWORD=$DB_PASSWORD
- MYSQL_DATABASE=$DB_NAME
volumes:
- db-data:/var/lib/mysql
ports:
- "3306:3306"
healthcheck:
test: [ "CMD", "mysqladmin", "ping", "-h", "localhost" ]
timeout: 20s
retries: 10

app:
container_name: app-docker
build: .
environment:
- PORT=$PORT
- DB_HOST=db
- DB_USERNAME=$DB_USERNAME
- DB_PASSWORD=$DB_PASSWORD
- DB_NAME=$DB_NAME
- DB_PORT=$DB_PORT
ports:
- "3000:80"
depends_on:
mysql:
condition: service_healthy
volumes:
db-data:
35 changes: 35 additions & 0 deletions infrastructure/setup-instance.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh
set -e

sudo apt update
sudo apt upgrade -y

sudo apt-get install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings

# install docker
for pkg in docker.io docker-doc docker-compose podman-docker containerd runc; do sudo apt-get remove $pkg; done

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
# Add the repository to Apt sources:
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update

sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin

# create github user
sudo mkdir -p /home/app
sudo useradd --no-create-home --home-dir /home/app --shell /bin/bash github
sudo usermod --append --groups docker github
sudo usermod --append --groups docker ubuntu
sudo chown github:github -R /home/app

github_pubkey='ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIH/nuLtOesRq8NPmQT/Lurvz/qPsgpwyIPzyAyZIaD43 sarah@Sarah-Lenovo'

sudo -u github sh -c "mkdir -p /home/app/.ssh && echo $github_pubkey > /home/app/.ssh/authorized_keys"

sudo reboot
3 changes: 3 additions & 0 deletions jest.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"testTimeout": 20000
}
12 changes: 12 additions & 0 deletions logger.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import winston from "winston";

const baseLogger = winston.createLogger({
format: winston.format.json(),
defaultMeta: { project: 'serve and shine', time: new Date() },
transports: [
new winston.transports.File({ filename: 'logger/error.log', level: 'error' }),
//new winston.transports.File({ filename: 'logger/all.log' }),
],
});

export default baseLogger;
Loading
Loading