enable data saving
This commit is contained in:
@@ -1 +1 @@
|
||||
{}
|
||||
{"2024-10-03T07:36:00.000Z":{"day":"2024-10-03T07:36:00.000Z","count":0,"difficulty":3,"sleep":7,"rest":3,"freeTime":2,"stress":3}}
|
||||
@@ -11,9 +11,7 @@ if ( typeof __dirname === 'undefined' ) {
|
||||
}
|
||||
|
||||
declare module 'express-session' {
|
||||
interface SessionData {
|
||||
'isAuth': boolean;
|
||||
}
|
||||
interface SessionData { 'isAuth': boolean; }
|
||||
}
|
||||
|
||||
const run = () => {
|
||||
@@ -30,7 +28,6 @@ const run = () => {
|
||||
} ) );
|
||||
app.set( 'trust proxy', 1 );
|
||||
|
||||
app.use( bodyParser.urlencoded( { 'extended': false } ) );
|
||||
app.use( bodyParser.json() );
|
||||
|
||||
|
||||
@@ -62,6 +59,7 @@ const run = () => {
|
||||
let data = {};
|
||||
try {
|
||||
data = JSON.parse( '' + fs.readFileSync( path.join( __dirname + '/data/batu.json' ) ) );
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
} catch ( err ) { /* empty */ }
|
||||
response.send( data );
|
||||
} else {
|
||||
@@ -83,12 +81,23 @@ const run = () => {
|
||||
stressLevel: number;
|
||||
*/
|
||||
|
||||
if ( body.count && body.day && body.difficulty ) {
|
||||
if ( body.count !== undefined && body.day !== undefined && body.difficulty !== undefined ) {
|
||||
let data = {};
|
||||
try {
|
||||
data = JSON.parse( '' + fs.readFileSync( path.join( __dirname + '/data/batu.json' ) ) );
|
||||
} catch ( err ) { /* empty */ }
|
||||
data[ body.day ] = '';
|
||||
} catch ( err ) {
|
||||
console.error( err );
|
||||
response.status( 500 ).send( 'ERR_STORING' );
|
||||
return;
|
||||
}
|
||||
data[ body.day ] = body;
|
||||
try {
|
||||
fs.writeFileSync( path.join( __dirname + '/data/batu.json' ), JSON.stringify( data ) );
|
||||
} catch ( err ) {
|
||||
console.error( err );
|
||||
response.status( 500 ).send( 'ERR_STORING' );
|
||||
return;
|
||||
}
|
||||
response.send( 'stored' );
|
||||
} else {
|
||||
response.status( 400 ).send( 'ERR_INVALID_REQ' );
|
||||
|
||||
@@ -7,9 +7,7 @@ import stylistic from '@stylistic/eslint-plugin';
|
||||
export default tseslint.config(
|
||||
eslint.configs.recommended,
|
||||
...tseslint.configs.recommended,
|
||||
{
|
||||
'ignores': [ '**/dist/', '**/*.cjs' ],
|
||||
},
|
||||
{ 'ignores': [ '**/dist/', '**/*.cjs' ], },
|
||||
{
|
||||
'plugins': {
|
||||
'@stylistic/js': stylistic,
|
||||
@@ -23,7 +21,7 @@ export default tseslint.config(
|
||||
'@stylistic/js/arrow-parens': [ 'error', 'always' ],
|
||||
'@stylistic/js/arrow-spacing': [ 'error', { 'before': true, 'after': true } ],
|
||||
'@stylistic/js/block-spacing': [ 'error', 'always' ],
|
||||
'@stylistic/js/brace-style': [ 'error', '1tbs' ],
|
||||
// '@stylistic/js/brace-style': [ 'error', '1tbs' ],
|
||||
'@stylistic/js/comma-spacing': [ 'error', { 'before': false, 'after': true } ],
|
||||
'@stylistic/js/comma-style': [ 'error', 'last' ],
|
||||
'@stylistic/js/dot-location': [ 'error', 'property' ],
|
||||
|
||||
@@ -118,7 +118,30 @@
|
||||
}
|
||||
|
||||
const sendForm = () => {
|
||||
fetch( localStorage.getItem( 'url' ) + '/update', {
|
||||
method: 'post',
|
||||
body: JSON.stringify( {
|
||||
day: date.value?.toISOString(),
|
||||
count: cigaretCount.value,
|
||||
difficulty: difficulty.value,
|
||||
sleep: sleepHours.value,
|
||||
rest: rest.value,
|
||||
freeTime: freeTime.value,
|
||||
stress: stress.value
|
||||
} ),
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'charset': 'utf-8'
|
||||
}
|
||||
} ).then( res => {
|
||||
if ( res.status === 200 ) {
|
||||
alert( 'Data submitted. Remember: Stop smoking! Smoking hurts your health!' );
|
||||
} else {
|
||||
alert( `Failed to save data (${ res.status })` );
|
||||
}
|
||||
} );
|
||||
|
||||
}
|
||||
|
||||
const dateUpdatedHandler = () => {
|
||||
|
||||
@@ -43,6 +43,7 @@
|
||||
transform-origin: center;
|
||||
transform: scale(0);
|
||||
transition: all 0.5s;
|
||||
z-index: 50;
|
||||
}
|
||||
|
||||
.stats-view-shown {
|
||||
|
||||
Reference in New Issue
Block a user