diff --git a/api/api-doc.js b/api/api-doc.js index ae40f6a..58df4ca 100644 --- a/api/api-doc.js +++ b/api/api-doc.js @@ -12,29 +12,95 @@ const apiDoc = { version: "1.0.0", }, definitions: { - Todo: { + Account: { type: "object", - properties: { + properties: { id: { - type: "number", + type: "number" }, - message: { - type: "string", + id_card_type: { + type: "number" }, - }, - required: ["id", "message"], - }, - User: { - type: "object", - properties: { - id: { + email: { + type: "string" + }, + username: { + type: "string" + }, + nim: { + type: "string" + }, + nama: { + type: "string" + }, + password: { + type: "string" + }, + password_plain: { + type: "string" + }, + phone: { type: "number" + }, + tanggal_lahir: { + type: "string" + }, + tempat_lahir: { + type: "string" + }, + account_type: { + type: "string" + }, + namafile: { + type: "string" + }, + pendidikan: { + type: "string" }, - name : { + id_prodi : { type: "string" }, - gender : { + universitas : { type: "string" + }, + fakultas : { + type: "string" + }, + jurusan : { + type: "string" + }, + tahun_lulus : { + type: "string" + }, + comp_bidang_usaha : { + type: "string" + }, + comp_deskripsi : { + type: "string" + }, + comp_website : { + type: "string" + }, + comp_contact_person : { + type: "string" + }, + comp_alamat : { + type: "string" + }, + date_created : { + type: "number" + }, + date_updated : { + type: "number" + }, + time_created : { + type: "number" + }, + time_updated : { + type: "number" + }, + status : { + type: "number" } } } diff --git a/api/config/database.js b/api/config/database.js new file mode 100644 index 0000000..16a553a --- /dev/null +++ b/api/config/database.js @@ -0,0 +1,14 @@ +const mysql = require('mysql'); +const connection = mysql.createConnection({ + host : "localhost", + user : "root", + password : "", + database : "m2_expo", + port: 3307 +}); + +connection.connect(function(err){ + if(err) throw err; +}) + +module.exports = connection; \ No newline at end of file diff --git a/api/paths/users/index.js b/api/paths/account/index.js similarity index 60% rename from api/paths/users/index.js rename to api/paths/account/index.js index bfa8410..c989555 100644 --- a/api/paths/users/index.js +++ b/api/paths/account/index.js @@ -1,3 +1,5 @@ +const db = require('../../config/database'); +const table = 'rexpo_account' module.exports = function () { let operations = { GET, @@ -7,10 +9,26 @@ module.exports = function () { }; function GET(req, res, next) { - res.status(200).json([ - { id: 0, message: "First User" }, - { id: 1, message: "Second User" }, - ]); + let query = `SELECT id, + id_card, + id_card_type, + email, + username, + nama, + phone, + tanggal_lahir, + tempat_lahir, + account_type, + namafile, + pendidikan FROM `+table+``; + db.query(query, function(error, rows, fields){ + if(error){ + console.log(error); + res.status(400).json({error: 'Request failed'}) + }else{ + res.status(200).json(rows); + } + }); } function POST(req, res, next) { @@ -29,15 +47,15 @@ module.exports = function () { } GET.apiDoc = { - summary: "Fetch users.", - operationId: "getTodos", + summary: "Fetch account.", + operationId: "getAccount", responses: { 200: { - description: "List of todos.", + description: "List of account.", schema: { type: "array", items: { - $ref: "#/definitions/Todo", + $ref: "#/definitions/Account", }, }, }, @@ -45,15 +63,15 @@ module.exports = function () { }; POST.apiDoc = { - summary: "Create users.", - operationId: "createTodo", + summary: "Create account.", + operationId: "createAccount", consumes: ["application/json"], parameters: [ { in: "body", name: "todo", schema: { - $ref: "#/definitions/Todo", + $ref: "#/definitions/Account", }, }, ], @@ -65,8 +83,8 @@ module.exports = function () { }; PUT.apiDoc = { - summary: "Update users.", - operationId: "updateTodo", + summary: "Update account.", + operationId: "updateAccount", parameters: [ { in: "query", @@ -78,7 +96,7 @@ module.exports = function () { in: "body", name: "todo", schema: { - $ref: "#/definitions/Todo", + $ref: "#/definitions/Account", }, }, ], @@ -90,8 +108,8 @@ module.exports = function () { }; DELETE.apiDoc = { - summary: "Delete users.", - operationId: "deleteTodo", + summary: "Delete account.", + operationId: "deleteAccount", consumes: ["application/json"], parameters: [ { diff --git a/api/paths/todos/index.js b/backup/todos/index.js similarity index 100% rename from api/paths/todos/index.js rename to backup/todos/index.js