|
@@ -1,7 +1,13 @@
|
|
import fs from 'fs'
|
|
import fs from 'fs'
|
|
|
|
+import awaitFs from 'await-fs'
|
|
import express from 'express'
|
|
import express from 'express'
|
|
import bhttp from 'bhttp'
|
|
import bhttp from 'bhttp'
|
|
-import excel from '../../excel'
|
|
|
|
|
|
+import Excel from '../excel'
|
|
|
|
+import Player from '../models/player'
|
|
|
|
+import Match from '../models/match'
|
|
|
|
+import PlayerList from '../models/playerList'
|
|
|
|
+import MatchList from '../models/matchList'
|
|
|
|
+import { normalize, normalizePhone } from '../helpers'
|
|
|
|
|
|
// Create the router
|
|
// Create the router
|
|
const swisstennis = express.Router()
|
|
const swisstennis = express.Router()
|
|
@@ -14,22 +20,18 @@ function fileDate (date) {
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
- * Define the Routes
|
|
|
|
- */
|
|
|
|
|
|
+* Define the Routes
|
|
|
|
+*/
|
|
|
|
|
|
// Login
|
|
// Login
|
|
swisstennis.post('/login', async (req, res) => {
|
|
swisstennis.post('/login', async (req, res) => {
|
|
const { username, password } = req.body
|
|
const { username, password } = req.body
|
|
-
|
|
|
|
|
|
+
|
|
// return, if username or password are missing
|
|
// return, if username or password are missing
|
|
if (!username || !password) {
|
|
if (!username || !password) {
|
|
- res.status(400).json({
|
|
|
|
- success: false,
|
|
|
|
- msg: 'Parameters username and password are required'
|
|
|
|
- })
|
|
|
|
- return
|
|
|
|
|
|
+ return res.status(400).json({ msg: 'Parameters username and password are required' })
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// assemble the login data
|
|
// assemble the login data
|
|
const loginData = {
|
|
const loginData = {
|
|
Lang: 'D',
|
|
Lang: 'D',
|
|
@@ -37,31 +39,21 @@ swisstennis.post('/login', async (req, res) => {
|
|
pwd: password,
|
|
pwd: password,
|
|
Tournament: ''
|
|
Tournament: ''
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
try {
|
|
try {
|
|
const myTournamentsPage = await session.get('https://comp.swisstennis.ch/advantage/servlet/MyTournamentList?Lang=D')
|
|
const myTournamentsPage = await session.get('https://comp.swisstennis.ch/advantage/servlet/MyTournamentList?Lang=D')
|
|
const loginPage = await session.post('https://comp.swisstennis.ch/advantage/servlet/Login', loginData)
|
|
const loginPage = await session.post('https://comp.swisstennis.ch/advantage/servlet/Login', loginData)
|
|
const strLoginPage = loginPage.body.toString()
|
|
const strLoginPage = loginPage.body.toString()
|
|
if (strLoginPage.includes('Zugriff verweigert')) {
|
|
if (strLoginPage.includes('Zugriff verweigert')) {
|
|
- res.status(400).json({
|
|
|
|
- success: false,
|
|
|
|
- msg: 'Access denied!'
|
|
|
|
- })
|
|
|
|
- return
|
|
|
|
|
|
+ return res.status(400).json({ msg: 'Access denied!' })
|
|
}
|
|
}
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- res.status(400).json({
|
|
|
|
- success: false,
|
|
|
|
- msg: error
|
|
|
|
- })
|
|
|
|
- return
|
|
|
|
|
|
+ return res.status(400).json({ msg: error })
|
|
}
|
|
}
|
|
- res.json({
|
|
|
|
- success: true,
|
|
|
|
- msg: 'Logged in successfully.'
|
|
|
|
- })
|
|
|
|
|
|
+ res.json({ msg: 'Logged in successfully.' })
|
|
})
|
|
})
|
|
|
|
|
|
|
|
+// Overview of tournaments
|
|
swisstennis.get('/tournaments', async (req, res) => {
|
|
swisstennis.get('/tournaments', async (req, res) => {
|
|
const tournaments = {}
|
|
const tournaments = {}
|
|
try {
|
|
try {
|
|
@@ -69,14 +61,10 @@ swisstennis.get('/tournaments', async (req, res) => {
|
|
const myTournamentsPage = await session.get('https://comp.swisstennis.ch/advantage/servlet/MyTournamentList?Lang=D')
|
|
const myTournamentsPage = await session.get('https://comp.swisstennis.ch/advantage/servlet/MyTournamentList?Lang=D')
|
|
const strMyTournamentsPage = myTournamentsPage.body.toString()
|
|
const strMyTournamentsPage = myTournamentsPage.body.toString()
|
|
if (strMyTournamentsPage.includes('Login-Zone')) {
|
|
if (strMyTournamentsPage.includes('Login-Zone')) {
|
|
- res.status(400).json({
|
|
|
|
- success: false,
|
|
|
|
- message: 'Not logged in.'
|
|
|
|
- })
|
|
|
|
- return
|
|
|
|
|
|
+ return res.status(400).json({ message: 'Not logged in.' })
|
|
}
|
|
}
|
|
const tournamentRegexp = /<a href=".*ProtectedDisplayTournament.*tournament=Id(\d+)">([^<]+)<\/a>/gm
|
|
const tournamentRegexp = /<a href=".*ProtectedDisplayTournament.*tournament=Id(\d+)">([^<]+)<\/a>/gm
|
|
-
|
|
|
|
|
|
+
|
|
do {
|
|
do {
|
|
match = tournamentRegexp.exec(strMyTournamentsPage)
|
|
match = tournamentRegexp.exec(strMyTournamentsPage)
|
|
if (match) {
|
|
if (match) {
|
|
@@ -84,27 +72,17 @@ swisstennis.get('/tournaments', async (req, res) => {
|
|
}
|
|
}
|
|
} while (match)
|
|
} while (match)
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- res.status(400).json({
|
|
|
|
- success: false,
|
|
|
|
- msg: error.toString()
|
|
|
|
- })
|
|
|
|
- return
|
|
|
|
|
|
+ return res.status(400).json({ msg: error.toString() })
|
|
}
|
|
}
|
|
- res.json({
|
|
|
|
- success: true,
|
|
|
|
- tournaments
|
|
|
|
- })
|
|
|
|
|
|
+ res.json({ tournaments })
|
|
})
|
|
})
|
|
|
|
|
|
|
|
+// Draws of a tournament
|
|
swisstennis.get('/draws/:tournament', async (req, res) => {
|
|
swisstennis.get('/draws/:tournament', async (req, res) => {
|
|
const { tournament } = req.params
|
|
const { tournament } = req.params
|
|
-
|
|
|
|
|
|
+
|
|
if (!tournament) {
|
|
if (!tournament) {
|
|
- res.json({
|
|
|
|
- success: false,
|
|
|
|
- msg: 'No tournament given.'
|
|
|
|
- })
|
|
|
|
- return
|
|
|
|
|
|
+ return res.json({ msg: 'No tournament given.' })
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
let match
|
|
let match
|
|
@@ -112,127 +90,230 @@ swisstennis.get('/draws/:tournament', async (req, res) => {
|
|
const tournamentPage = await session.get(`https://comp.swisstennis.ch/advantage/servlet/ProtectedDisplayTournament?Lang=D&tournament=Id${tournament}`)
|
|
const tournamentPage = await session.get(`https://comp.swisstennis.ch/advantage/servlet/ProtectedDisplayTournament?Lang=D&tournament=Id${tournament}`)
|
|
const strTournamentPage = tournamentPage.body.toString()
|
|
const strTournamentPage = tournamentPage.body.toString()
|
|
if (strTournamentPage.includes('Login-Zone')) {
|
|
if (strTournamentPage.includes('Login-Zone')) {
|
|
- res.status(400).json({
|
|
|
|
- success: false,
|
|
|
|
- message: 'Not logged in.'
|
|
|
|
- })
|
|
|
|
- return
|
|
|
|
|
|
+ return res.status(400).json({ message: 'Not logged in.' })
|
|
}
|
|
}
|
|
const drawRegexp = /<a (?:class="text" )?href=".*DisplayEvent.*eventId=(\d+).*">([^<]+)<\/a>/gm
|
|
const drawRegexp = /<a (?:class="text" )?href=".*DisplayEvent.*eventId=(\d+).*">([^<]+)<\/a>/gm
|
|
-
|
|
|
|
|
|
+
|
|
do {
|
|
do {
|
|
match = drawRegexp.exec(strTournamentPage)
|
|
match = drawRegexp.exec(strTournamentPage)
|
|
if (match) {
|
|
if (match) {
|
|
draws[match[1]] = match[2]
|
|
draws[match[1]] = match[2]
|
|
}
|
|
}
|
|
} while (match)
|
|
} while (match)
|
|
- res.json({
|
|
|
|
- success: true,
|
|
|
|
- draws
|
|
|
|
- })
|
|
|
|
|
|
+ return res.json({ draws })
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- res.status(400).json({
|
|
|
|
- success: false,
|
|
|
|
- msg: error.toString()
|
|
|
|
- })
|
|
|
|
|
|
+ return res.status(400).json({ msg: error.toString() })
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
|
|
-swisstennis.get('/download/playerlist/:tournament', async (req, res) => {
|
|
|
|
|
|
+// Download a playerlist
|
|
|
|
+swisstennis.get('/playerlist/download/:tournament', async (req, res) => {
|
|
const { tournament } = req.params
|
|
const { tournament } = req.params
|
|
-
|
|
|
|
|
|
+
|
|
if (!tournament) {
|
|
if (!tournament) {
|
|
- res.json({
|
|
|
|
- success: false,
|
|
|
|
- msg: 'No tournament given.'
|
|
|
|
- })
|
|
|
|
- return
|
|
|
|
|
|
+ return res.json({ msg: 'No tournament given.' })
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
const playerListFile = fs.createWriteStream(`swisstennis_files/PlayerList-${fileDate(new Date())}.xls`)
|
|
const playerListFile = fs.createWriteStream(`swisstennis_files/PlayerList-${fileDate(new Date())}.xls`)
|
|
const playerList = await session.get(`https://comp.swisstennis.ch/advantage/servlet/PlayerList.xls?tournament=Id${tournament}&lang=D`, {stream: true})
|
|
const playerList = await session.get(`https://comp.swisstennis.ch/advantage/servlet/PlayerList.xls?tournament=Id${tournament}&lang=D`, {stream: true})
|
|
playerList.pipe(playerListFile)
|
|
playerList.pipe(playerListFile)
|
|
- res.json({
|
|
|
|
- success: true,
|
|
|
|
- msg: 'Download successful.'
|
|
|
|
- })
|
|
|
|
|
|
+ return res.json({ msg: 'Download successful.' })
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- res.status(400).json({
|
|
|
|
- success: false,
|
|
|
|
- msg: error.toString()
|
|
|
|
|
|
+ return res.status(400).json({ msg: error.toString() })
|
|
|
|
+ }
|
|
|
|
+})
|
|
|
|
+
|
|
|
|
+swisstennis.get('/playerlist/parse/:filename', async (req, res) => {
|
|
|
|
+ try {
|
|
|
|
+ console.log('Parsing file', req.params.filename)
|
|
|
|
+
|
|
|
|
+ const filePath = `swisstennis_files/${req.params.filename}`
|
|
|
|
+ const dateElems = req.params.filename.match(/\w+\-(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})\.xls/).slice(1,7)
|
|
|
|
+ const fileDate = new Date(`${dateElems[0]}-${dateElems[1]}-${dateElems[2]} ${dateElems[3]}:${dateElems[4]}:${dateElems[5]}`)
|
|
|
|
+ const stat = fs.statSync(filePath)
|
|
|
|
+
|
|
|
|
+ console.log('About to read the player list.')
|
|
|
|
+ const worksheets = await Excel.readWorkbook(filePath)
|
|
|
|
+ const worksheet = worksheets.Players
|
|
|
|
+ if (worksheet[4].length !== 32 & worksheet[3][0] !== 'Konkurrenz' & worksheet[3][31] !== 'bezahlt') {
|
|
|
|
+ throw Error(`Wrong file structure. Length: ${worksheet[4].length} (expected 32), Column A name: ${worksheet[3][0]} (expected Konkurrenz).`)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const headers = worksheet.slice(3, 4)
|
|
|
|
+
|
|
|
|
+ const dbPlayers = await Player.find().lean()
|
|
|
|
+ console.log(dbPlayers.slice(0,3))
|
|
|
|
+
|
|
|
|
+ const allPlayers = worksheet.slice(4, worksheet.length).map(data => {
|
|
|
|
+ const filePlayer = {
|
|
|
|
+ created: new Date(),
|
|
|
|
+ category: normalize(data[0]),
|
|
|
|
+ licenseNr: normalize(data[2]),
|
|
|
|
+ name: normalize(data[5]),
|
|
|
|
+ firstName: normalize(data[6]),
|
|
|
|
+ nameDP: normalize(data[24]),
|
|
|
|
+ firstNameDP: normalize(data[25]),
|
|
|
|
+ birthDate: data[7],
|
|
|
|
+ email: normalize(data[16]),
|
|
|
|
+ ranking: normalize(data[17]),
|
|
|
|
+ licenseNrDP: normalize(data[23]),
|
|
|
|
+ phonePrivate: normalizePhone(data[13]),
|
|
|
|
+ phoneWork: normalizePhone(data[14]),
|
|
|
|
+ phoneMobile: normalizePhone(data[15]),
|
|
|
|
+ birthDateDP: data[26],
|
|
|
|
+ rankingDP: normalize(data[27]),
|
|
|
|
+ confirmed: data[29],
|
|
|
|
+ paid: data[31],
|
|
|
|
+ }
|
|
|
|
+ filePlayer.gender = filePlayer.category ?
|
|
|
|
+ filePlayer.category[0] === 'M' ? 'm' :
|
|
|
|
+ filePlayer.category[0] === 'W' ?
|
|
|
|
+ 'w' :
|
|
|
|
+ null :
|
|
|
|
+ null,
|
|
|
|
+ filePlayer.doubles = !!filePlayer.category.match(/DM.*|[MW]D.*/)
|
|
|
|
+ filePlayer.junior = filePlayer.birthDate ?
|
|
|
|
+ filePlayer.birthDate.getTime() >= (new Date((new Date()).getFullYear() - 19, 11, 31, 23, 59, 59, 999)).getTime() :
|
|
|
|
+ false
|
|
|
|
+ filePlayer.fullName = filePlayer.doubles ?
|
|
|
|
+ `${filePlayer.name} ${filePlayer.firstName} / ${filePlayer.nameDP} ${filePlayer.firstNameDP}` :
|
|
|
|
+ `${filePlayer.name} ${filePlayer.firstName}`
|
|
|
|
+ filePlayer.idString = `${filePlayer.category} % ${filePlayer.fullName}`
|
|
|
|
+ filePlayer.phone = null
|
|
|
|
+ const reMobile = /^\+417/
|
|
|
|
+ if (filePlayer.phoneWork && filePlayer.phoneWork.match(reMobile)) {
|
|
|
|
+ filePlayer.phone = filePlayer.phoneWork
|
|
|
|
+ } else if (filePlayer.phonePrivate && filePlayer.phonePrivate.match(reMobile)) {
|
|
|
|
+ filePlayer.phone = filePlayer.phonePrivate
|
|
|
|
+ } else if (filePlayer.phoneMobile && filePlayer.phoneMobile.match(reMobile)) {
|
|
|
|
+ filePlayer.phone = filePlayer.phoneMobile
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ const dbPlayer = dbPlayers.filter(player => player.idString == filePlayer.idString).sort((a, b) =>
|
|
|
|
+ a.created > b.created ? 1 : a.created == b.created ? 0 : -1
|
|
|
|
+ )[0]
|
|
|
|
+ console.log('sorted:', dbPlayer)
|
|
|
|
+
|
|
|
|
+ if (filePlayer != dbPlayer) {
|
|
|
|
+ const player = new Player(filePlayer)
|
|
|
|
+ player.save()
|
|
|
|
+ return player._id
|
|
|
|
+ } else {
|
|
|
|
+ return dbPlayer._id
|
|
|
|
+ }
|
|
})
|
|
})
|
|
|
|
+
|
|
|
|
+ const playerList = new PlayerList({
|
|
|
|
+ imported: new Date(),
|
|
|
|
+ file: req.params.filename,
|
|
|
|
+ fileSize: stat.size,
|
|
|
|
+ players: allPlayers
|
|
|
|
+ })
|
|
|
|
+ playerList.save()
|
|
|
|
+
|
|
|
|
+ return res.json({ playerList })
|
|
|
|
+ } catch (error) {
|
|
|
|
+ return res.status(400).json({ msg: error.toString() })
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
|
|
-swisstennis.get('/download/calendar/:tournament', async (req, res) => {
|
|
|
|
|
|
+// List downloaded files
|
|
|
|
+swisstennis.get('/files/list/:tournament', async (req, res) => {
|
|
const { tournament } = req.params
|
|
const { tournament } = req.params
|
|
-
|
|
|
|
|
|
+
|
|
if (!tournament) {
|
|
if (!tournament) {
|
|
- res.json({
|
|
|
|
- success: false,
|
|
|
|
- msg: 'No tournament given.'
|
|
|
|
|
|
+ return res.json({ msg: 'No tournament given.' })
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ const dirContent = await awaitFs.readdir('swisstennis_files')
|
|
|
|
+ const fileList = dirContent.filter(filename => {
|
|
|
|
+ console.log(filename)
|
|
|
|
+ return filename.includes(tournament) || true
|
|
|
|
+ }).map(filename => {
|
|
|
|
+ console.log(filename)
|
|
|
|
+ const stats = fs.statSync(`swisstennis_files/${filename}`)
|
|
|
|
+ return { [filename]: stats.size }
|
|
})
|
|
})
|
|
- return
|
|
|
|
|
|
+ return res.json({ fileList })
|
|
|
|
+ } catch (error) {
|
|
|
|
+ return res.status(400).json({ msg: error.toString() })
|
|
|
|
+ }
|
|
|
|
+})
|
|
|
|
+
|
|
|
|
+swisstennis.get('/calendar/download/:tournament', async (req, res) => {
|
|
|
|
+ const { tournament } = req.params
|
|
|
|
+
|
|
|
|
+ if (!tournament) {
|
|
|
|
+ return res.json({ msg: 'No tournament given.' })
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
const calendarFile = fs.createWriteStream(`swisstennis_files/Calendar-${fileDate(new Date())}.xls`)
|
|
const calendarFile = fs.createWriteStream(`swisstennis_files/Calendar-${fileDate(new Date())}.xls`)
|
|
const calendar = await session.get(`https://comp.swisstennis.ch/advantage/servlet/Calendar.xls?Lang=D&tournament=Id${tournament}&Type=Match&Inp_DateRangeFilter.fromDate=04.06.2018&Inp_DateRangeFilter.toDate=16.09.2018`, {stream: true})
|
|
const calendar = await session.get(`https://comp.swisstennis.ch/advantage/servlet/Calendar.xls?Lang=D&tournament=Id${tournament}&Type=Match&Inp_DateRangeFilter.fromDate=04.06.2018&Inp_DateRangeFilter.toDate=16.09.2018`, {stream: true})
|
|
calendar.pipe(calendarFile)
|
|
calendar.pipe(calendarFile)
|
|
- res.json({
|
|
|
|
- success: true,
|
|
|
|
- msg: 'Download successful.'
|
|
|
|
- })
|
|
|
|
|
|
+ return res.json({ msg: 'Download successful.' })
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- res.status(400).json({
|
|
|
|
- success: false,
|
|
|
|
- msg: error.toString()
|
|
|
|
- })
|
|
|
|
|
|
+ return res.status(400).json({ msg: error.toString() })
|
|
|
|
+ }
|
|
|
|
+})
|
|
|
|
+
|
|
|
|
+swisstennis.get('/calendar/parse/:filename', async (req,res) => {
|
|
|
|
+ try {
|
|
|
|
+ console.log('Parsing file', req.params.filename)
|
|
|
|
+ console.log('About to read the calendar list.')
|
|
|
|
+
|
|
|
|
+ const worksheets = await Excel.readWorkbook(`swisstennis_files/${req.params.filename}`)
|
|
|
|
+ const worksheet = worksheets.Sheet1
|
|
|
|
+ if (worksheet[2].length < 8 | worksheet[2].length > 9) {
|
|
|
|
+ throw Error(`Wrong file structure.`)
|
|
|
|
+ }
|
|
|
|
+ const calendar = await Promise.all(worksheet.slice(2, worksheet.length).map(async data => {
|
|
|
|
+ const category = normalize(data[3])
|
|
|
|
+ const player1 = await Player.findOne({idString: `${category} % ${normalize(data[4])}`})
|
|
|
|
+ const player2 = await Player.findOne({idString: `${category} % ${normalize(data[6])}`})
|
|
|
|
+ const match = new Match({
|
|
|
|
+ _created: Date.now(),
|
|
|
|
+ idString: "String",
|
|
|
|
+ place: normalize(data[0]),
|
|
|
|
+ date: data[1],
|
|
|
|
+ category,
|
|
|
|
+ player1: player1 ? player1._id : null,
|
|
|
|
+ player2: player2 ? player2._id : null,
|
|
|
|
+ result: normalize(data[8] || null),
|
|
|
|
+ doubles: !!category.match(/DM.*|[MW]D.*/)
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ match.save()
|
|
|
|
+ return match
|
|
|
|
+ }))
|
|
|
|
+ res.json(calendar)
|
|
|
|
+ } catch (error) {
|
|
|
|
+ res.status(400).json({ msg: error.toString() })
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
|
|
swisstennis.get('/download/draw/:draw', async (req, res) => {
|
|
swisstennis.get('/download/draw/:draw', async (req, res) => {
|
|
const { draw } = req.params
|
|
const { draw } = req.params
|
|
-
|
|
|
|
|
|
+
|
|
if (!draw) {
|
|
if (!draw) {
|
|
- res.json({
|
|
|
|
- success: false,
|
|
|
|
- msg: 'No draw given.'
|
|
|
|
- })
|
|
|
|
- return
|
|
|
|
|
|
+ return res.json({ msg: 'No draw given.' })
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
const fileName = `DisplayDraw${draw}-${fileDate(new Date())}.xls`
|
|
const fileName = `DisplayDraw${draw}-${fileDate(new Date())}.xls`
|
|
const drawFile = fs.createWriteStream(`swisstennis_files/${fileName}`)
|
|
const drawFile = fs.createWriteStream(`swisstennis_files/${fileName}`)
|
|
const drawDisplay = await session.get(`https://comp.swisstennis.ch/advantage/servlet/DisplayDraw.xls?eventId=${draw}&lang=D`, {stream: true})
|
|
const drawDisplay = await session.get(`https://comp.swisstennis.ch/advantage/servlet/DisplayDraw.xls?eventId=${draw}&lang=D`, {stream: true})
|
|
drawDisplay.pipe(drawFile)
|
|
drawDisplay.pipe(drawFile)
|
|
- res.json({
|
|
|
|
- success: true,
|
|
|
|
- fileName
|
|
|
|
- })
|
|
|
|
|
|
+ return res.json({ fileName })
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- res.status(400).json({
|
|
|
|
- success: false,
|
|
|
|
- msg: error.toString()
|
|
|
|
- })
|
|
|
|
|
|
+ return res.status(400).json({ msg: error.toString() })
|
|
}
|
|
}
|
|
})
|
|
})
|
|
|
|
|
|
-function generatePlayerList (file) {
|
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
|
- console.log('About to read the player list.')
|
|
|
|
- Excel.readWorkbook(file).then(worksheets => {
|
|
|
|
- console.log('got worksheets', worksheets)
|
|
|
|
- const worksheet = worksheets.Players
|
|
|
|
- if (worksheet[4].length !== 32 & worksheet[3][0] !== 'Konkurrenz' & worksheet[3][31] !== 'bezahlt') {
|
|
|
|
- reject(Error(`Wrong file structure. Length: ${worksheet[4].length} (expected 32), Column A name: ${worksheet[3][0]} (expected Konkurrenz)`))
|
|
|
|
- }
|
|
|
|
- const headers = worksheet.slice(3, 1)
|
|
|
|
- const allPlayers = worksheet.slice(4, worksheet.length).map(playerData => new Player.Player(playerData))
|
|
|
|
- resolve({ headers, allPlayers })
|
|
|
|
- }).catch(error => {
|
|
|
|
- reject(Error(`Error reading workbook ${error.toString()}`))
|
|
|
|
- })
|
|
|
|
- })
|
|
|
|
-}
|
|
|
|
|
|
+swisstennis.get('/schedule/generate/:id', async (req, res) => {
|
|
|
|
+ return res.status(400).json({ msg: 'Not implemented' })
|
|
|
|
+})
|
|
|
|
+
|
|
|
|
+swisstennis.get('/paylist/generate/:id', async (req, res) => {
|
|
|
|
+ return res.status(400).json({ msg: 'Not implemented' })
|
|
|
|
+})
|
|
|
|
|
|
export default swisstennis
|
|
export default swisstennis
|