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

Merge dev to main #1

Merged
merged 9 commits into from
Dec 17, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Ajout typeORM
  • Loading branch information
FrozyPenguin committed Dec 3, 2021
commit 93eb29439bae48f7b6fe31d7d042e0671f791f8e
2,163 changes: 2,086 additions & 77 deletions package-lock.json

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
"express": "^4.17.1",
"joi": "^17.4.2",
"morgan": "^1.10.0",
"rotating-file-stream": "^3.0.2"
"reflect-metadata": "^0.1.13",
"rotating-file-stream": "^3.0.2",
"sqlite3": "^5.0.2",
"typeorm": "^0.2.41"
},
"devDependencies": {
"@types/cors": "^2.8.12",
Expand Down
25 changes: 25 additions & 0 deletions src/database/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import 'reflect-metadata';
import { createConnection, ConnectionOptions, Connection } from 'typeorm';
import * as path from 'path';

let connection: Connection | null;

const options: ConnectionOptions = {
type: 'sqlite',
database: path.resolve(__dirname, './gpao.db'),
entities: [path.resolve(__dirname, '../models/*.ts')],
logging: true
}

async function connect() {
try {
connection = await createConnection(options);
}
catch(e) {
throw e;
}

return connection;
}

export { connection, connect };
12 changes: 11 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as Morgan from 'morgan';
import { createStream } from 'rotating-file-stream';
import * as path from 'path';
import * as cors from 'cors';
import { connect } from './database';
import recursiveTreeReader from './utils/recursiveTreeReader';
import posixNormalize from './utils/posixNormalize';
import print from './utils/printAllExpressRoutes';
Expand All @@ -14,6 +15,15 @@ let app = null;
(async () => {
app = Express();

// Connection à la bdd
try {
await connect();
}
catch(e) {
console.error('Impossible de se connecter à la base de donnée');
process.exit(1);
}

/**
* Utilisation du logger HTTP Morgan
* un fichier log sera créé par jour et placé dans le dossier logs
Expand Down Expand Up @@ -46,7 +56,7 @@ let app = null;

// Importation automatique des routes
const routesFolder = path.join(__dirname, 'routes');
const routes: Array<string> = await recursiveTreeReader(routesFolder);
const routes: string[] = await recursiveTreeReader(routesFolder);
for (let route of routes) {
// Suppréssion de l'extension
route = route.replace(/\.[^/.]+$/, '');
Expand Down
2 changes: 2 additions & 0 deletions src/models/Articles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ export interface Article {
PF_ou_MP_ou_Piece_ou_SE: ArticleType;
}

// TODO: create Entity

export const articles = Joi.object({
reference: Joi.string().alphanum().required().min(4).max(10),
designation: Joi.string()
Expand Down
1 change: 1 addition & 0 deletions src/models/Generator.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://www.npmjs.com/package/typeorm-model-generator
2 changes: 2 additions & 0 deletions src/models/Lien_de_nomenclatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ export interface LienDeNomenclature {
quantite_de_composition: number;
}

// TODO: create Entity

export const lienDeNomenclature = Joi.object({
compose: Joi.string().alphanum().required().min(4).max(10),
composant: Joi.string().alphanum().required().min(4).max(10),
Expand Down
2 changes: 2 additions & 0 deletions src/models/MouvementsDeStocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ export interface MouvementsDeStock {
// NOT YET IMPLEMENTED
}

// TODO: create Entity

export const mouvementsDeStock = Joi.object({});
2 changes: 2 additions & 0 deletions src/models/Operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ export interface Operation {
// NOT YET IMPLEMENTED
}

// TODO: create Entity

export const operation = Joi.object({});
2 changes: 2 additions & 0 deletions src/models/PosteDeCharges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ export interface PosteDeCharge {
// NOT YET IMPLEMENTED
}

// TODO: create Entity

export const posteDeCharge = Joi.object({});
2 changes: 2 additions & 0 deletions src/models/Remplacements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ export interface Remplacement {
remplacant_composant: Article;
date_de_remplacement: Date;
}

// TODO: create Entity
4 changes: 3 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"strictNullChecks": true,
"target": "ESNext",
"strict": true,
"resolveJsonModule": true
"resolveJsonModule": true,
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"exclude": [
"node_modules",
Expand Down