create-sip 1.3.1 → 1.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,41 +0,0 @@
1
- {
2
- "name": "expressapi",
3
- "version": "0.0.1",
4
- "description": "Express API with simple Sequelize",
5
- "main": "index.js",
6
- "scripts": {
7
- "test": "NODE_ENV=test mocha",
8
- "dev": "nodemon app --watch app --watch config",
9
- "start": "node app"
10
- },
11
- "keywords": [
12
- "express",
13
- "api"
14
- ],
15
- "author": "your name",
16
- "license": "ISC",
17
- "dependencies": {
18
- "@dotenvx/dotenvx": "^1.51.0",
19
- "bcryptjs": "^2.4.3",
20
- "cors": "^2.8.5",
21
- "express": "^4.18.2",
22
- "generate-api-key": "^1.0.2",
23
- "jsonwebtoken": "^9.0.0",
24
- "mariadb": "^3.1.2",
25
- "morgan": "^1.10.0",
26
- "read": "^4.1.0",
27
- "replace": "^1.2.2",
28
- "sequelize": "^6.32.0",
29
- "sqlite3": "^5.1.6",
30
- "umzug": "^3.8.2",
31
- "yargs": "^18.0.0"
32
- },
33
- "devDependencies": {
34
- "@types/bcryptjs": "^2.4.6",
35
- "fs-extra": "^11.3.0",
36
- "mocha": "^11.7.4",
37
- "nodemon": "^2.0.22",
38
- "supertest": "^6.3.3"
39
- },
40
- "type": "module"
41
- }
@@ -1,121 +0,0 @@
1
- import Thing from '../models/thing.js'
2
-
3
- const ThingController = {
4
- async index(req, res) {
5
- try {
6
- await ThingController.tryIndex(req, res)
7
- }catch(error) {
8
- res.status(500)
9
- res.json({
10
- success: false,
11
- message: 'Error! The query is failed!',
12
- error: error.message
13
- })
14
- }
15
- },
16
- async tryIndex(req, res) {
17
- const things = await Thing.findAll()
18
- res.status(200)
19
- res.json({
20
- success: true,
21
- data: things
22
- })
23
- },
24
- async show(req, res) {
25
- try {
26
- await ThingController.tryShow(req, res)
27
- }catch(error) {
28
- res.status(500)
29
- res.json({
30
- success: false,
31
- message: 'Error! The query is failed!',
32
- error: error.message
33
- })
34
- }
35
- },
36
- async tryShow(req, res) {
37
- const thing = await Thing.findByPk(req.params.id)
38
- res.status(200)
39
- res.json({
40
- success: true,
41
- data: thing
42
- })
43
- },
44
- async store(req, res) {
45
- try {
46
- await ThingController.tryStore(req, res)
47
- }catch(error) {
48
- res.status(500)
49
- res.json({
50
- success: false,
51
- message: 'Error! The query is failed!',
52
- error: error.message
53
- })
54
- }
55
- },
56
- async tryStore(req, res) {
57
- const thing = await Thing.create(req.body)
58
- res.status(201)
59
- res.json({
60
- success: true,
61
- data: thing
62
- })
63
- },
64
- async update(req, res) {
65
- try {
66
- await ThingController.tryUpdate(req, res)
67
- }catch(error) {
68
- let actualMessage = '';
69
- if(error.message == 'Fail! Record not found!') {
70
- actualMessage = error.message
71
- res.status(404)
72
- }else {
73
- res.status(500)
74
- actualMessage = 'Fail! The query is failed!'
75
- }
76
-
77
- res.json({
78
- success: false,
79
- message: actualMessage
80
- })
81
- }
82
- },
83
- async tryUpdate(req, res) {
84
- const recordNumber = await Thing.update(req.body, {
85
- where: { id: req.params.id }
86
- })
87
- if(recordNumber == 0) {
88
- throw new Error('Fail! Record not found!')
89
- }
90
- const thing = await Thing.findByPk(req.params.id)
91
- res.status(200)
92
- res.json({
93
- success: true,
94
- data: thing
95
- })
96
- },
97
- async destroy(req, res) {
98
- try {
99
- await ThingController.tryDestroy(req, res)
100
- }catch(error) {
101
- res.status(500)
102
- res.json({
103
- success: false,
104
- message: 'Error! The query is failed!',
105
- error: error.message
106
- })
107
- }
108
- },
109
- async tryDestroy(req, res) {
110
- const thing = await Thing.destroy({
111
- where: { id: req.params.id }
112
- })
113
- res.status(200)
114
- res.json({
115
- success: true,
116
- data: thing
117
- })
118
- }
119
- }
120
-
121
- export default ThingController
@@ -1,21 +0,0 @@
1
- import { DataTypes } from 'sequelize';
2
-
3
- async function up({context: QueryInterface}) {
4
- await QueryInterface.createTable('things', {
5
- id: {
6
- allowNull: false,
7
- autoIncrement: true,
8
- primaryKey: true,
9
- type: DataTypes.INTEGER
10
- },
11
- name: {
12
- type: DataTypes.STRING
13
- }
14
- });
15
- }
16
-
17
- async function down({context: QueryInterface}) {
18
- await QueryInterface.dropTable('things');
19
- }
20
-
21
- export { up, down }
@@ -1,8 +0,0 @@
1
- import { DataTypes } from 'sequelize'
2
- import sequelize from '../database/database.js'
3
-
4
- const Thing = sequelize.define('thing', {
5
- name: { type: DataTypes.STRING, allowNull: false }
6
- })
7
-
8
- export default Thing
@@ -1,43 +0,0 @@
1
- import supertest from 'supertest'
2
- import app from '../app/app.js'
3
-
4
- describe('/api/register and /api/login', () => {
5
- const restype= 'application/json; charset=utf-8'
6
- var token = null
7
-
8
- it('post /register ', function(done) {
9
- supertest(app)
10
- .post('/api/register')
11
- .set('Accept', 'application/json')
12
- .send({
13
- name: 'mari',
14
- email: 'mari@zold.lan',
15
- password: 'titok',
16
- password_confirmation: 'titok'
17
- })
18
- .expect('Content-Type', restype)
19
- .expect(201, done)
20
-
21
- })
22
- it('post /login ', (done) => {
23
- supertest(app)
24
- .post('/api/login')
25
- .set('Accept', 'application/json')
26
- .send({
27
- name: 'mari',
28
- password: 'titok'
29
- })
30
- .expect('Content-Type', restype)
31
- .expect(200, done)
32
- .expect(res => {
33
- token = res.body.accessToken
34
- })
35
- })
36
- it('get /users ', function(done) {
37
- supertest(app)
38
- .get('/api/users')
39
- .set('Accept', 'application/json')
40
- .set('Authorization', 'Bearer ' + token)
41
- .expect(200, done)
42
- })
43
- })
@@ -1,17 +0,0 @@
1
-
2
- import fsp from 'fs/promises'
3
- import path from 'path'
4
-
5
- async function readJson(dirPath) {
6
- try {
7
- const filePath = path.resolve(dirPath);
8
- const data = await fsp.readFile(filePath, 'utf8');
9
- const dataObject = JSON.parse(data);
10
- return dataObject;
11
- } catch (error) {
12
- console.error('Error loading config:', error);
13
- return null;
14
- }
15
- }
16
-
17
- export { readJson }
package/mockapi/README.md DELETED
@@ -1 +0,0 @@
1
- # Sinto Fake REST API
@@ -1,26 +0,0 @@
1
- {
2
- "employees": [
3
- {
4
- "id": 1,
5
- "name": "Strong Steven",
6
- "city": "Szeged",
7
- "salary": 395
8
- },
9
- {
10
- "id": 2,
11
- "name": "John Doe",
12
- "city": "New York",
13
- "salary": 392
14
- }
15
- ],
16
- "positions": [
17
- {
18
- "id": 1,
19
- "name": "Manager"
20
- },
21
- {
22
- "id": 2,
23
- "name": "Developer"
24
- }
25
- ]
26
- }
@@ -1,4 +0,0 @@
1
- {
2
- "port": 8000,
3
- "watch": true
4
- }
@@ -1,15 +0,0 @@
1
- {
2
- "name": "mockapi",
3
- "version": "1.0.0",
4
- "description": "Mock REST API server",
5
- "main": "index.js",
6
- "scripts": {
7
- "start": "hai-server database.json"
8
- },
9
- "keywords": [],
10
- "author": "",
11
- "license": "ISC",
12
- "dependencies": {
13
- "hai-server": "^0.0.4"
14
- }
15
- }