Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tma-backend
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Denys Tito Urbano
tma-backend
Commits
c3b799ec
Commit
c3b799ec
authored
Oct 01, 2022
by
Denys Tito Urbano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Router auth modificado (salida de post_login) y Helper error_json agregado
parent
e5b4691f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
19 deletions
+34
-19
auth.controller.js
controllers/auth.controller.js
+12
-13
horario.controller.js
controllers/horario.controller.js
+2
-1
material.controller.js
controllers/material.controller.js
+3
-2
error_json.js
helpers/error_json.js
+11
-0
index.js
helpers/index.js
+6
-3
No files found.
controllers/auth.controller.js
View file @
c3b799ec
const
service
=
require
(
'../services/auth.service'
);
const
{
generate_jwt
}
=
require
(
'../helpers'
);
const
{
generate_jwt
,
error_json
}
=
require
(
'../helpers'
);
const
post_login
=
async
(
req
,
res
)
=>
{
try
{
const
{
email
,
password
}
=
req
.
body
;
const
{
json
:
user
}
=
await
service
.
post_login
({
email
,
password
});
const
salida
=
await
service
.
post_login
({
email
,
password
});
const
{
json
}
=
salida
;
const
{
data
:
{
documento
}
}
=
json
;
const
access_token
=
await
generate_jwt
({
email
,
documento
});
json
[
'data'
].
access_token
=
access_token
;
if
(
!
user
)
{
res
.
status
(
400
).
json
({
message
:
'Usuario / Contraseña incorrecta'
});
}
const
accessToken
=
await
generate_jwt
({
email
,
documento
:
user
.
documento
});
res
.
json
({
accessToken
,
user
});
res
.
json
(
json
);
}
catch
(
error
)
{
res
.
status
(
400
).
json
(
{
error
}
);
res
.
status
(
400
).
json
(
error_json
(
error
.
message
)
);
}
};
const
get_account
=
async
(
req
,
res
)
=>
{
try
{
const
{
documento
}
=
req
.
params
;
const
{
json
:
user
}
=
await
service
.
get_account
({
documento
});
const
salida
=
await
service
.
get_account
({
documento
});
const
{
json
}
=
salida
;
res
.
json
(
{
user
}
);
res
.
json
(
json
);
}
catch
(
error
)
{
res
.
status
(
400
).
json
(
{
error
}
);
res
.
status
(
400
).
json
(
error_json
(
error
.
message
)
);
}
};
...
...
controllers/horario.controller.js
View file @
c3b799ec
const
service
=
require
(
'../services/horario.service'
);
const
{
error_json
}
=
require
(
'../helpers'
);
const
get_horario
=
async
(
req
,
res
)
=>
{
try
{
...
...
@@ -7,7 +8,7 @@ const get_horario = async (req, res) => {
res
.
json
(
salida
);
}
catch
(
error
)
{
res
.
status
(
400
).
json
(
{
error
}
);
res
.
status
(
400
).
json
(
error_json
(
error
.
message
)
);
}
};
...
...
controllers/material.controller.js
View file @
c3b799ec
const
service
=
require
(
'../services/material.service'
);
const
{
error_json
}
=
require
(
'../helpers'
);
const
get_materiales
=
async
(
req
,
res
)
=>
{
try
{
...
...
@@ -7,7 +8,7 @@ const get_materiales = async (req, res) => {
res
.
json
(
salida
);
}
catch
(
error
)
{
res
.
status
(
400
).
json
(
{
message
:
error
.
message
}
);
res
.
status
(
400
).
json
(
error_json
(
error
.
message
)
);
}
};
...
...
@@ -18,7 +19,7 @@ const get_material = async (req, res) => {
res
.
json
(
salida
);
}
catch
(
error
)
{
res
.
status
(
400
).
json
(
{
message
:
error
.
message
}
);
res
.
status
(
400
).
json
(
error_json
(
error
.
message
)
);
}
};
...
...
helpers/error_json.js
0 → 100644
View file @
c3b799ec
const
error_json
=
(
input
)
=>
{
try
{
return
JSON
.
parse
(
input
);
}
catch
(
error
)
{
return
{
status
:
false
,
message
:
input
};
}
};
module
.
exports
=
{
error_json
};
helpers/index.js
View file @
c3b799ec
const
{
download_file
}
=
require
(
'.
./helpers
/download_file'
);
const
{
download_file
}
=
require
(
'./download_file'
);
const
{
generate_jwt
}
=
require
(
'./generate_jwt'
);
const
{
format_timestamp
}
=
require
(
'../helpers/format_timestamp'
);
const
{
format_timestamp
}
=
require
(
'./format_timestamp'
);
const
{
error_json
}
=
require
(
'./error_json'
);
module
.
exports
=
{
download_file
,
generate_jwt
,
format_timestamp
format_timestamp
,
error_json
};
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment