correct scripts and db

This commit is contained in:
Arthur Barre 2024-12-17 11:49:31 +01:00
parent 99f98508af
commit 3e32834455
5 changed files with 220 additions and 79 deletions

View File

@ -11,7 +11,9 @@
"dependencies": { "dependencies": {
"@fastify/cors": "^10.0.1", "@fastify/cors": "^10.0.1",
"@prisma/client": "^6.0.1", "@prisma/client": "^6.0.1",
"axios": "^1.7.9",
"bcrypt": "^5.1.1", "bcrypt": "^5.1.1",
"dotenv": "^16.4.7",
"fastify": "^5.1.0", "fastify": "^5.1.0",
"jsonwebtoken": "^9.0.2", "jsonwebtoken": "^9.0.2",
"prisma": "^6.0.1", "prisma": "^6.0.1",
@ -365,6 +367,12 @@
"node": "^12.13.0 || ^14.15.0 || >=16.0.0" "node": "^12.13.0 || ^14.15.0 || >=16.0.0"
} }
}, },
"node_modules/asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==",
"license": "MIT"
},
"node_modules/atomic-sleep": { "node_modules/atomic-sleep": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/atomic-sleep/-/atomic-sleep-1.0.0.tgz", "resolved": "https://registry.npmjs.org/atomic-sleep/-/atomic-sleep-1.0.0.tgz",
@ -384,6 +392,17 @@
"fastq": "^1.17.1" "fastq": "^1.17.1"
} }
}, },
"node_modules/axios": {
"version": "1.7.9",
"resolved": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz",
"integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==",
"license": "MIT",
"dependencies": {
"follow-redirects": "^1.15.6",
"form-data": "^4.0.0",
"proxy-from-env": "^1.1.0"
}
},
"node_modules/balanced-match": { "node_modules/balanced-match": {
"version": "1.0.2", "version": "1.0.2",
"resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz",
@ -548,6 +567,18 @@
"color-support": "bin.js" "color-support": "bin.js"
} }
}, },
"node_modules/combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"license": "MIT",
"dependencies": {
"delayed-stream": "~1.0.0"
},
"engines": {
"node": ">= 0.8"
}
},
"node_modules/concat-map": { "node_modules/concat-map": {
"version": "0.0.1", "version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@ -610,6 +641,15 @@
"node": ">=4.0.0" "node": ">=4.0.0"
} }
}, },
"node_modules/delayed-stream": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
"license": "MIT",
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/delegates": { "node_modules/delegates": {
"version": "1.0.0", "version": "1.0.0",
"resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz",
@ -625,6 +665,18 @@
"node": ">=8" "node": ">=8"
} }
}, },
"node_modules/dotenv": {
"version": "16.4.7",
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.4.7.tgz",
"integrity": "sha512-47qPchRCykZC03FhkYAhrvwU4xDBFIj1QPqaarj6mdM/hgUzfPHcpkHJOn3mJAufFeeAxAzeGsr5X0M4k6fLZQ==",
"license": "BSD-2-Clause",
"engines": {
"node": ">=12"
},
"funding": {
"url": "https://dotenvx.com"
}
},
"node_modules/ecdsa-sig-formatter": { "node_modules/ecdsa-sig-formatter": {
"version": "1.0.11", "version": "1.0.11",
"resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz", "resolved": "https://registry.npmjs.org/ecdsa-sig-formatter/-/ecdsa-sig-formatter-1.0.11.tgz",
@ -810,6 +862,40 @@
"node": ">=14" "node": ">=14"
} }
}, },
"node_modules/follow-redirects": {
"version": "1.15.9",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.9.tgz",
"integrity": "sha512-gew4GsXizNgdoRyqmyfMHyAmXsZDk6mHkSxZFCzW9gwlbtOW44CDtYavM+y+72qD/Vq2l550kMF52DT8fOLJqQ==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"license": "MIT",
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/form-data": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.1.tgz",
"integrity": "sha512-tzN8e4TX8+kkxGPK8D5u0FNmjPUjw3lwC9lSLxxoB/+GtsJG91CO8bSWy73APlgAZzZbXEYZJuxjkHH2w+Ezhw==",
"license": "MIT",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/forwarded": { "node_modules/forwarded": {
"version": "0.2.0", "version": "0.2.0",
"resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz", "resolved": "https://registry.npmjs.org/forwarded/-/forwarded-0.2.0.tgz",
@ -1275,6 +1361,27 @@
"node": ">= 10" "node": ">= 10"
} }
}, },
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"license": "MIT",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"license": "MIT",
"dependencies": {
"mime-db": "1.52.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mimic-response": { "node_modules/mimic-response": {
"version": "3.1.0", "version": "3.1.0",
"resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz", "resolved": "https://registry.npmjs.org/mimic-response/-/mimic-response-3.1.0.tgz",
@ -1727,6 +1834,12 @@
"node": ">= 0.10" "node": ">= 0.10"
} }
}, },
"node_modules/proxy-from-env": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
"license": "MIT"
},
"node_modules/pump": { "node_modules/pump": {
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/pump/-/pump-3.0.2.tgz", "resolved": "https://registry.npmjs.org/pump/-/pump-3.0.2.tgz",

View File

@ -3,6 +3,7 @@ const Fastify = require('fastify')
const cors = require('@fastify/cors') const cors = require('@fastify/cors')
const jwt = require('jsonwebtoken') const jwt = require('jsonwebtoken')
const bcrypt = require('bcrypt') const bcrypt = require('bcrypt')
const path = require('path')
// Import des routes // Import des routes
const customerRoutes = require('./routes/customers') const customerRoutes = require('./routes/customers')
@ -11,19 +12,14 @@ const purchaseRoutes = require('./routes/purchases')
const artistRoutes = require('./routes/artists') const artistRoutes = require('./routes/artists')
const userRoutes = require('./routes/users') const userRoutes = require('./routes/users')
const clientRoutes = require('./routes/clients') const clientRoutes = require('./routes/clients')
// const prisma = new PrismaClient()
const prisma = new PrismaClient({ const prisma = new PrismaClient()
datasources: {
db: {
url: process.env.DATABASE_URL || 'file:./data/db.sqlite'
}
}
})
const fastify = Fastify({ logger: true }) const fastify = Fastify({ logger: true })
// Plugins // Plugins
fastify.register(cors, { fastify.register(cors, {
origin: ['http://localhost:8090'], origin: ['*'],
credentials: true, credentials: true,
methods: ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS'], methods: ['GET', 'PUT', 'POST', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization'] allowedHeaders: ['Content-Type', 'Authorization']
@ -130,5 +126,17 @@ fastify.register(async (fastify) => {
// fastify.register(userRoutes, { prefix: '/api' }) // fastify.register(userRoutes, { prefix: '/api' })
}) })
// Ajoute ce code temporairement dans index.js
// const initDb = async () => {
// await prisma.user.create({
// data: {
// email: "admin@example.com",
// password: await bcrypt.hash("password123", 10),
// role: "ADMIN"
// }
// })
// }
// initDb()
// Démarrage du serveur // Démarrage du serveur
fastify.listen({ port: 3000, host: '0.0.0.0' }) fastify.listen({ port: 3000, host: '0.0.0.0' })

View File

@ -1,5 +1,6 @@
const { PrismaClient } = require('@prisma/client') const { PrismaClient } = require('@prisma/client')
const axios = require('axios'); const axios = require('axios');
const bcrypt = require('bcrypt');
// const data = require('../../data.json') // const data = require('../../data.json')
@ -19,22 +20,40 @@ async function cleanDb() {
console.log('Base de données nettoyée!') console.log('Base de données nettoyée!')
} }
const API_URL = 'https://lh.logiciel-arteo.fr/api/purchase/'; const API_URL = 'http://109.199.98.72/json/2ba06bde-5b67-408e-a972-e8065bf2a438';
async function seed() { async function seed() {
try { try {
// await cleanDb() await cleanDb()
await prisma.user.create({
data: {
email: "admin@example.com",
password: await bcrypt.hash("password123", 10),
role: "ADMIN"
}
})
// Créer le client par défaut // Créer le client par défaut
// const defaultClient = await prisma.client.upsert({ const defaultClient = await prisma.client.upsert({
// where: { id: 1 }, where: { id: 1 },
// update: {}, update: {},
// create: { create: {
// id: 1, id: 1,
// name: "Ghost", name: "Ghost",
// url: API_URL url: API_URL
// } }
// }) })
const secondClient = await prisma.client.upsert({
where: { id: 2 },
update: {},
create: {
id: 2,
name: "Client 2",
url: null
}
})
const response = await axios.get(API_URL); const response = await axios.get(API_URL);
const dataArray = response.data; const dataArray = response.data;
@ -185,7 +204,7 @@ async function seed() {
type: { connect: { id: item.product?.type?.id || 1 } }, type: { connect: { id: item.product?.type?.id || 1 } },
state: { connect: { id: 1 } }, state: { connect: { id: 1 } },
acquisitionMode: { connect: { id: item.product?.acquisition_mode?.id || 1 } }, acquisitionMode: { connect: { id: item.product?.acquisition_mode?.id || 1 } },
client: { connect: { id: 2 } } client: { connect: { id: 1 } }
} }
}) })
) )
@ -223,5 +242,6 @@ async function seed() {
await prisma.$disconnect() await prisma.$disconnect()
} }
} }
// cleanDb()
seed() seed()
// seed()

View File

@ -241,7 +241,7 @@ base64-js@^1.3.1:
bcrypt@^5.1.1: bcrypt@^5.1.1:
version "5.1.1" version "5.1.1"
resolved "https://registry.npmjs.org/bcrypt/-/bcrypt-5.1.1.tgz" resolved "https://registry.yarnpkg.com/bcrypt/-/bcrypt-5.1.1.tgz#0f732c6dcb4e12e5b70a25e326a72965879ba6e2"
integrity sha512-AGBHOG5hPYZ5Xl9KXzU5iKq9516yEmvCKDg3ecP5kX2aB6UqTeXZxk2ELnDgDm6BQSMlLt9rDB4LoSMx0rYwww== integrity sha512-AGBHOG5hPYZ5Xl9KXzU5iKq9516yEmvCKDg3ecP5kX2aB6UqTeXZxk2ELnDgDm6BQSMlLt9rDB4LoSMx0rYwww==
dependencies: dependencies:
"@mapbox/node-pre-gyp" "^1.0.11" "@mapbox/node-pre-gyp" "^1.0.11"

View File

@ -1,57 +1,57 @@
/** @type {import('tailwindcss').Config} */ /** @type {import('tailwindcss').Config} */
module.exports = { export default {
darkMode: ["class"], darkMode: ["class"],
content: ["./index.html", "./src/**/*.{ts,tsx,js,jsx}"], content: ["./index.html", "./src/**/*.{ts,tsx,js,jsx}"],
theme: { theme: {
extend: { extend: {
borderRadius: { borderRadius: {
lg: 'var(--radius)', lg: 'var(--radius)',
md: 'calc(var(--radius) - 2px)', md: 'calc(var(--radius) - 2px)',
sm: 'calc(var(--radius) - 4px)' sm: 'calc(var(--radius) - 4px)'
}, },
colors: { colors: {
background: 'hsl(var(--background))', background: 'hsl(var(--background))',
foreground: 'hsl(var(--foreground))', foreground: 'hsl(var(--foreground))',
card: { card: {
DEFAULT: 'hsl(var(--card))', DEFAULT: 'hsl(var(--card))',
foreground: 'hsl(var(--card-foreground))' foreground: 'hsl(var(--card-foreground))'
}, },
popover: { popover: {
DEFAULT: 'hsl(var(--popover))', DEFAULT: 'hsl(var(--popover))',
foreground: 'hsl(var(--popover-foreground))' foreground: 'hsl(var(--popover-foreground))'
}, },
primary: { primary: {
DEFAULT: 'hsl(var(--primary))', DEFAULT: 'hsl(var(--primary))',
foreground: 'hsl(var(--primary-foreground))' foreground: 'hsl(var(--primary-foreground))'
}, },
secondary: { secondary: {
DEFAULT: 'hsl(var(--secondary))', DEFAULT: 'hsl(var(--secondary))',
foreground: 'hsl(var(--secondary-foreground))' foreground: 'hsl(var(--secondary-foreground))'
}, },
muted: { muted: {
DEFAULT: 'hsl(var(--muted))', DEFAULT: 'hsl(var(--muted))',
foreground: 'hsl(var(--muted-foreground))' foreground: 'hsl(var(--muted-foreground))'
}, },
accent: { accent: {
DEFAULT: 'hsl(var(--accent))', DEFAULT: 'hsl(var(--accent))',
foreground: 'hsl(var(--accent-foreground))' foreground: 'hsl(var(--accent-foreground))'
}, },
destructive: { destructive: {
DEFAULT: 'hsl(var(--destructive))', DEFAULT: 'hsl(var(--destructive))',
foreground: 'hsl(var(--destructive-foreground))' foreground: 'hsl(var(--destructive-foreground))'
}, },
border: 'hsl(var(--border))', border: 'hsl(var(--border))',
input: 'hsl(var(--input))', input: 'hsl(var(--input))',
ring: 'hsl(var(--ring))', ring: 'hsl(var(--ring))',
chart: { chart: {
'1': 'hsl(var(--chart-1))', '1': 'hsl(var(--chart-1))',
'2': 'hsl(var(--chart-2))', '2': 'hsl(var(--chart-2))',
'3': 'hsl(var(--chart-3))', '3': 'hsl(var(--chart-3))',
'4': 'hsl(var(--chart-4))', '4': 'hsl(var(--chart-4))',
'5': 'hsl(var(--chart-5))' '5': 'hsl(var(--chart-5))'
} }
} }
} }
}, },
plugins: [require("tailwindcss-animate")], plugins: [require("tailwindcss-animate")],
} }