mirror of
https://github.com/Alamantus/Lexiconga.git
synced 2025-06-07 01:36:37 +02:00
Update words to the database
This commit is contained in:
parent
7e7ffb8525
commit
23263051f5
3 changed files with 24 additions and 8 deletions
|
@ -137,12 +137,7 @@ class User {
|
||||||
$dictionary = $user_data->dictionary;
|
$dictionary = $user_data->dictionary;
|
||||||
$updated_words = $this->dictionary->setWords($dictionary, $words);
|
$updated_words = $this->dictionary->setWords($dictionary, $words);
|
||||||
if ($updated_words > 0) {
|
if ($updated_words > 0) {
|
||||||
if ($updated_words === count($words)) {
|
return true;
|
||||||
return true;
|
|
||||||
} else if ($updated_words < count($words)) {
|
|
||||||
// TODO: Handle this
|
|
||||||
return 'mostly';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -186,12 +186,12 @@ switch ($action) {
|
||||||
), 200);
|
), 200);
|
||||||
}
|
}
|
||||||
return Response::json(array(
|
return Response::json(array(
|
||||||
'data' => 'Could not set dictionary: invalid token',
|
'data' => 'Could not set words: invalid token',
|
||||||
'error' => true,
|
'error' => true,
|
||||||
), 401);
|
), 401);
|
||||||
}
|
}
|
||||||
return Response::json(array(
|
return Response::json(array(
|
||||||
'data' => 'Could not set dictionary: required data missing',
|
'data' => 'Could not set words: required data missing',
|
||||||
'error' => true,
|
'error' => true,
|
||||||
), 400);
|
), 400);
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,6 +49,7 @@ export class Word {
|
||||||
.then((id) => {
|
.then((id) => {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
console.log('Word added successfully');
|
console.log('Word added successfully');
|
||||||
|
this.send();
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
@ -61,6 +62,7 @@ export class Word {
|
||||||
return wordDb.words.put(this)
|
return wordDb.words.put(this)
|
||||||
.then((id) => {
|
.then((id) => {
|
||||||
console.log('Word modified successfully');
|
console.log('Word modified successfully');
|
||||||
|
this.send();
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
@ -76,4 +78,23 @@ export class Word {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
send () {
|
||||||
|
const request = new Request('./api/', {
|
||||||
|
method: 'POST',
|
||||||
|
mode: 'cors',
|
||||||
|
redirect: 'follow',
|
||||||
|
headers: new Headers({
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
}),
|
||||||
|
body: JSON.stringify({
|
||||||
|
action: 'set-dictionary-words',
|
||||||
|
token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MTUxLCJpc01lbWJlciI6ZmFsc2UsImRpY3Rpb25hcnkiOjM1M30.4HRuWY8arkjjYLgQ0Cq4a6v-eXwLTD24oENL8E4I5o0',
|
||||||
|
words: [this],
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
return fetch(request).then(response => response.json()).then(responseJSON => {
|
||||||
|
console.log(responseJSON);
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue