-
Notifications
You must be signed in to change notification settings - Fork 49
Event link app #54
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
base: main
Are you sure you want to change the base?
Event link app #54
Changes from all commits
97725e8
a67bbab
44ba52e
d3dcd83
ed5a0d9
3b4fc6a
36f6d5d
99a3971
cc01281
77cc524
d95c439
218a86d
1fca08d
169ecc5
2dd3e65
629e9a9
97c2182
a638069
6cc4ad2
9bbde91
5e71a4a
33bce2b
b40a61b
b57595e
0e8606a
fa0ffd0
085e9ba
799ceb2
de3182c
3c53bae
0626bff
54b125c
7b612aa
71f7b15
5e252dd
d844bff
33066d4
1238540
a10749b
754647d
b605571
6abc533
c3dd4d3
3018d51
802b1af
323b8f3
30e148d
8cbc734
2db444f
643597b
bc966b4
ddd2589
f976eaa
0f38f73
e5ae8ef
0e6c40b
b7b8bd0
9d39e27
3ad6f5f
3862847
b91d5a7
918b12b
54abd50
2f8454a
63e5ed1
370346f
ab88916
ac6072f
ea9e208
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,25 @@ | ||
| node_modules/ | ||
| # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
|
||
| # dependencies | ||
| /node_modules | ||
| /.pnp | ||
| .pnp.js | ||
|
|
||
| # testing | ||
| /coverage | ||
|
|
||
| # production | ||
| /build | ||
|
|
||
| # misc | ||
| .DS_Store | ||
| .env.local | ||
| .env.development.local | ||
| .env.test.local | ||
| .env.production.local | ||
|
|
||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
|
|
||
| .env | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| const path = require("path"); | ||
|
|
||
| module.exports = { | ||
| config: path.resolve("config", "database.js"), | ||
| "models-path": path.resolve("db", "models"), | ||
| "seeders-path": path.resolve("db", "seeders"), | ||
| "migrations-path": path.resolve("db", "migrations"), | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| require("dotenv").config(); | ||
|
|
||
| module.exports = { | ||
| development: { | ||
| username: process.env.DB_USERNAME, | ||
| password: process.env.DB_PASSWORD, | ||
| database: process.env.DB_NAME, | ||
| host: process.env.DB_HOST, | ||
| dialect: process.env.DB_DIALECT, | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| const BaseController = require("./baseController"); | ||
|
|
||
| class AdminsController extends BaseController { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since you are not using the Jwt middleware, please note that you can just create admins easily |
||
| constructor(model) { | ||
| super(model); | ||
| } | ||
|
|
||
| // Create user database | ||
| async insertUser(req, res) { | ||
| const { email, name } = req.body; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should probably check that these values exist first, and also that they are of the proper type, before we create sth in the database with these |
||
| try { | ||
| const output = await this.model.findOrCreate({ | ||
| where: { email: email }, | ||
| defaults: { name: name }, | ||
| }); | ||
| return res.json(output); | ||
| } catch (err) { | ||
| console.log(err.message); | ||
| return res.status(400).json({ error: true, msg: err.message }); | ||
| } | ||
| } | ||
|
|
||
| async getUser(req, res) { | ||
| const { email } = req.body; | ||
| try { | ||
| const output = await this.model.findOne({ | ||
| where: { email: email }, | ||
| }); | ||
| return res.json(output); | ||
| } catch (err) { | ||
| console.log(err.message); | ||
| return res.status(400).json({ error: true, msg: err.message }); | ||
| } | ||
| } | ||
|
|
||
| async updateUserName(req, res) { | ||
| const { adminID } = req.params; | ||
| const { newName } = req.body; | ||
| try { | ||
| const admin = await this.model.findOne({ | ||
| where: { id: adminID }, | ||
| }); | ||
|
|
||
| if (!admin) { | ||
| return res.status(404).json({ error: true, msg: "Admin not found" }); | ||
| } | ||
|
|
||
| admin.name = newName; | ||
| await admin.save(); | ||
|
|
||
| return res.json({ success: true, msg: "Name updated successfully" }); | ||
| } catch (err) { | ||
| console.log(err.message); | ||
| return res.status(400).json({ error: true, msg: err.message }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| module.exports = AdminsController; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| class BaseController { | ||
| constructor(model) { | ||
| this.model = model; | ||
| } | ||
|
|
||
| async getAll(req, res) { | ||
| console.log(this.model); | ||
| try { | ||
| const output = await this.model.findAll(); | ||
| return res.json(output); | ||
| } catch (err) { | ||
| console.log(err); | ||
| return res.status(400).json({ error: true, msg: err }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| module.exports = BaseController; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no readme file