-
Notifications
You must be signed in to change notification settings - Fork 2
clean code #1
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: master
Are you sure you want to change the base?
clean code #1
Changes from all commits
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 |
|---|---|---|
|
|
@@ -10,9 +10,7 @@ const { | |
| limitText | ||
| } = require('./libraries/helpers'); | ||
| const generateHTML = require('./libraries/html-generator'); | ||
| const { | ||
| uploadFile | ||
| } = require('./libraries/bucketManager'); | ||
| const { uploadFile } = require('./libraries/bucketManager'); | ||
| const generateImage = require('./libraries/image-generator'); | ||
|
|
||
| const membersJSON = JSON.parse(fs.readFileSync('./members.json', 'utf-8')); | ||
|
|
@@ -40,7 +38,11 @@ app.post('/', async (req, res, next) => { | |
| } = req.body; | ||
|
|
||
| await login.login(email, password); | ||
| const pages = await Promise.all([login.getTicketList(), login.getEventlist(), login.getHandshakeList()]); | ||
| const pages = await Promise.all([ | ||
|
Member
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. agree with this, should've spanned multiple lines |
||
| login.getTicketList(), | ||
| login.getEventlist(), | ||
| login.getHandshakeList() | ||
| ]); | ||
| const attendance = login.combineShows(login.parseShowTickets(pages[0]), login.parseEvents(pages[1])); | ||
| const handshakes = login.parseHandshake(pages[2]); | ||
| const username = login.username; | ||
|
|
@@ -58,24 +60,20 @@ app.post('/', async (req, res, next) => { | |
| memberImagebuffers.push(membersJSON[memberName]); | ||
| handshakeRanks.push(`${limitText(memberName)} - ${handshakes[i].sum} kali` || null); | ||
| } | ||
| } | ||
|
|
||
| if (handshakes.length === 0) { | ||
| } else { | ||
|
Member
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. else will prone to error if we have unhandled case within the ifs, in this case, we know every possible case, so it's okay. |
||
| handshakeRanks.push('Tidak tersedia'); | ||
| memberImagebuffers.push(membersJSON.Empty); | ||
| } | ||
|
|
||
| if (attendance.length === 0) { | ||
| setlistRanks.push('Tidak tersedia'); | ||
| setlistImageBuffers.push(setlistJSON.Empty); | ||
| } | ||
|
|
||
| if (attendance.length > 0) { | ||
| const length = attendance.length > 3 ? 3 : attendance.length; | ||
| for (let i = 0; i < length; i++) { | ||
| setlistImageBuffers.push(setlistJSON[attendance[i].showName] || null); | ||
| setlistRanks.push(`${attendance[i].showName} - ${attendance[i].sum} kali` || null); | ||
| } | ||
| } else { | ||
| setlistRanks.push('Tidak tersedia'); | ||
| setlistImageBuffers.push(setlistJSON.Empty); | ||
| } | ||
|
|
||
| const slug = createSlug(username); | ||
|
|
@@ -103,7 +101,10 @@ app.post('/', async (req, res, next) => { | |
| userNameText: username | ||
| }); | ||
|
|
||
| const results = await Promise.all([uploadFile(`share/${slug}.png`, 'image/png', Buffer.from(image)), uploadFile(`share/${slug}.html`, 'text/html', Buffer.from(html))]); | ||
| const results = await Promise.all([ | ||
| uploadFile(`share/${slug}.png`, 'image/png', Buffer.from(image)), | ||
| uploadFile(`share/${slug}.html`, 'text/html', Buffer.from(html)) | ||
| ]); | ||
| if (results) { | ||
| res.send({ | ||
| resultUrl: `https://2020.ngidol.club/share/${slug}.html` | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,6 @@ | ||
| require('dotenv').config(); | ||
| const got = require('got'); | ||
| const { | ||
| CookieJar | ||
| } = require('tough-cookie'); | ||
| const { | ||
| JSDOM | ||
| } = require('jsdom'); | ||
| const { CookieJar } = require('tough-cookie'); | ||
| const { JSDOM } = require('jsdom'); | ||
|
|
||
| const ticketListUrl = 'mypage/ticket-list?lang=id'; | ||
| const eventListUrl = 'mypage/event-list?lang=id'; | ||
|
|
@@ -16,14 +11,6 @@ const setlist = ['Saka Agari', 'Matahari Milikku', 'Pajama Drive', 'Fajar Sang I | |
| const isSetlistName = text => setlist.some(setlistTitle => text ? text.includes(setlistTitle) : ''); | ||
| const getSetlistName = text => setlist.find(setlistTitle => text.includes(setlistTitle)); | ||
|
|
||
|
|
||
| // const { | ||
| // bootstrap | ||
| // } = require('global-agent'); | ||
| const e = require('express'); | ||
| // bootstrap(); | ||
|
|
||
|
|
||
| class Login { | ||
| constructor() { | ||
| const cookieJar = new CookieJar(); | ||
|
|
@@ -47,9 +34,7 @@ class Login { | |
| throw new Error("Alamat email atau Kata kunci salah"); | ||
| } | ||
|
|
||
| const { | ||
| document | ||
| } = (new JSDOM(resp.body)).window; | ||
| const { document } = (new JSDOM(resp.body)).window; | ||
| this.username = document.querySelector('.pinx').innerHTML; | ||
|
|
||
| } catch (e) { | ||
|
|
@@ -61,9 +46,9 @@ class Login { | |
| } | ||
| } | ||
|
|
||
| async getTicketList() { | ||
| getTicketList() { | ||
| try { | ||
| return await this.req.get(ticketListUrl, { | ||
| return this.req.get(ticketListUrl, { | ||
| resolveBodyOnly: true | ||
| }); | ||
| } catch (error) { | ||
|
|
@@ -75,9 +60,9 @@ class Login { | |
| } | ||
| } | ||
|
|
||
| async getEventlist() { | ||
| getEventlist() { | ||
| try { | ||
| return await this.req.get(eventListUrl, { | ||
| return this.req.get(eventListUrl, { | ||
|
Member
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. the catch inside this function will be useless then? I'm putting out catch in this function to avoid polluting the caller with handling got http error |
||
| resolveBodyOnly: true | ||
| }); | ||
| } catch (error) { | ||
|
|
@@ -89,9 +74,9 @@ class Login { | |
| } | ||
| } | ||
|
|
||
| async getHandshakeList() { | ||
| getHandshakeList() { | ||
| try { | ||
| return await this.req(handshakeUrl, { | ||
| return this.req(handshakeUrl, { | ||
| resolveBodyOnly: true | ||
| }); | ||
| } catch (error) { | ||
|
|
||
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.
which clean code standart are we using? why are you modifiying some into one line but leaving out the others?