chore(i18n,curriculum): update translations (#43324)

This commit is contained in:
camperbot
2021-08-27 09:24:25 -07:00
committed by GitHub
parent 313b2baa20
commit fd7e0f8568
8 changed files with 670 additions and 46 deletions

View File

@ -11,8 +11,6 @@ dashedName: move-a-relatively-positioned-element-with-css-offsets
Gli offset (scostamenti) CSS di `top` o `bottom`, e `left` o `right` dicono al browser di quanto spostare un elemento rispetto a dove risiederebbe nel normale flusso del documento. Stai allontanando un elemento da un dato punto, e questo sposta l'elemento lontano dal lato di riferimento (di fatto lo sposta nella direzione opposta). Come hai visto nell'ultima sfida, utilizzando l'offset `top` abbiamo spostato l'`h2` verso il basso. Allo stesso modo, usando un offset `left` sposterai un elemento verso destra. Gli offset (scostamenti) CSS di `top` o `bottom`, e `left` o `right` dicono al browser di quanto spostare un elemento rispetto a dove risiederebbe nel normale flusso del documento. Stai allontanando un elemento da un dato punto, e questo sposta l'elemento lontano dal lato di riferimento (di fatto lo sposta nella direzione opposta). Come hai visto nell'ultima sfida, utilizzando l'offset `top` abbiamo spostato l'`h2` verso il basso. Allo stesso modo, usando un offset `left` sposterai un elemento verso destra.
<img src='https://cdn-media-1.freecodecamp.org/imgr/eWWi3gZ.gif' alt='' />
# --instructions-- # --instructions--
Usa gli spostamenti CSS per spostare `h2` di 15 pixel verso destra e 10 pixel verso l'alto. Usa gli spostamenti CSS per spostare `h2` di 15 pixel verso destra e 10 pixel verso l'alto.

View File

@ -28,7 +28,7 @@ var ourStr = "I come first. " + "I come second.";
La stringa `I come first. I come second.` sarebbe visualizzata nella console. La stringa `I come first. I come second.` sarebbe visualizzata nella console.
# --instructions-- # --instructions--
Costruisci `myStr` dalle stringhe `This is the start.` e `This is the end.` usando l'operatore `+`. Costruisci `myStr` dalle stringhe `This is the start.` e `This is the end.` usando l'operatore `+`. Assicurati di includere uno spazio tra le due stringhe.
# --hints-- # --hints--

View File

@ -24,7 +24,7 @@ ourStr += "I come second.";
# --instructions-- # --instructions--
Costruisci `myStr` su diverse righe concatenando queste due stringhe: `This is the first sentence.` e `This is the second sentence.` usando l'operatore `+=`. Usa l'operatore `+=` in modo simile a quello mostrato nell'esempio. Inizia assegnando la prima stringa a `myStr`, quindi aggiungi la seconda. Costruisci `myStr` su diverse righe concatenando queste due stringhe: `This is the first sentence.` e `This is the second sentence.` usando l'operatore `+=`. Usa l'operatore `+=` in modo simile a quello mostrato nell'esempio e assicurati di includere uno spazio tra le due stringhe. Inizia assegnando la prima stringa a `myStr`, quindi aggiungi la seconda.
# --hints-- # --hints--

View File

@ -1,6 +1,6 @@
--- ---
id: 5a24c314108439a4d4036185 id: 5a24c314108439a4d4036185
title: Use && for a More Concise Conditional title: Usare && per un condizionale più conciso
challengeType: 6 challengeType: 6
forumTopicId: 301413 forumTopicId: 301413
dashedName: use--for-a-more-concise-conditional dashedName: use--for-a-more-concise-conditional

View File

@ -47,7 +47,7 @@ Log:
{ {
username: "fcc_test", username: "fcc_test",
count: 1, count: 1,
_id: "5fd01a41c5b5cf05d080502f", _id: "5fb5853f734231456ccb3b05",
log: [{ log: [{
description: "test", description: "test",
duration: 60, duration: 60,
@ -71,7 +71,24 @@ Log:
}; };
``` ```
Puoi fare una richiesta `POST` a `/api/users` con il dato `username` proveniente dal modulo per creare un nuovo utente. La risposta restituita sarà un oggetto con proprietà `username` e `_id`. Puoi mandare una richiesta `POST` a `/api/users` con dato `username` per creare un nuovo utente.
```js
async (getUserInput) => {
const url = getUserInput('url');
const res = await fetch(url + '/api/users', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `username=fcc_test_${Date.now()}`.substr(0, 29)
});
assert.isTrue(res.ok);
if(!res.ok) {
throw new Error(`${res.status} ${res.statusText}`)
};
};
```
La risposta restituita da `POST /api/users` con dato `username` sarà un oggetto con proprietà `username` e `_id`.
```js ```js
async (getUserInput) => { async (getUserInput) => {
@ -91,24 +108,89 @@ async (getUserInput) => {
}; };
``` ```
È possibile fare una richiesta `GET` a `/api/users` per ottenere un array di tutti gli utenti. Ogni elemento nell'array è un oggetto contenente lo `username` e l'`_id` dell'utente. Puoi fare una richiesta `GET` a `/api/users` per avere una lista di tutti gli utenti.
```js
async(getUserInput) => {
const url = getUserInput('url');
const res = await fetch(url + '/api/users');
assert.isTrue(res.ok);
if(!res.ok) {
throw new Error(`${res.status} ${res.statusText}`)
};
};
```
La richiesta `GET` a `/api/users` restituisce un array.
```js ```js
async(getUserInput) => { async(getUserInput) => {
const url = getUserInput('url'); const url = getUserInput('url');
const res = await fetch(url + '/api/users'); const res = await fetch(url + '/api/users');
if(res.ok){ if(res.ok){
const data = await res.json(); const users = await res.json();
assert.isArray(data); assert.isArray(users);
assert.isString(data[0].username); } else {
assert.isString(data[0]._id); throw new Error(`${res.status} ${res.statusText}`);
};
};
```
Ogni elemento nell'array restituito da `GET /api/users` è un oggetto contenete le proprietà `username` e `_id` dell'utente.
```js
async(getUserInput) => {
const url = getUserInput('url');
const res = await fetch(url + '/api/users');
if(res.ok){
const users = await res.json();
const user = users[0];
assert.exists(user);
assert.exists(user.username);
assert.exists(user._id);
assert.isString(user.username);
assert.isString(user._id);
} else {
throw new Error(`${res.status} ${res.statusText}`);
};
};
```
Puoi fare una richiesta `POST` a `/api/users/:_id/exercises` con dati `description`, `duration`, e facoltativamente `date`. Se nessuna data è fornita, la data corrente verrà usata.
```js
async (getUserInput) => {
const url = getUserInput('url');
const res = await fetch(url + '/api/users', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `username=fcc_test_${Date.now()}`.substr(0, 29)
});
if (res.ok) {
const { _id, username } = await res.json();
const expected = {
username,
description: 'test',
duration: 60,
_id,
date: 'Mon Jan 01 1990'
};
const addRes = await fetch(url + `/api/users/${_id}/exercises`, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `description=${expected.description}&duration=${expected.duration}&date=1990-01-01`
});
assert.isTrue(addRes.ok);
if(!addRes.ok) {
throw new Error(`${addRes.status} ${addRes.statusText}`)
};
} else { } else {
throw new Error(`${res.status} ${res.statusText}`); throw new Error(`${res.status} ${res.statusText}`);
} }
}; };
``` ```
È possibile fare una richiesta `POST` a `/api/users/:_id/exercises` con i dati del modulo `description`, `duration` e, facoltativamente `date`. Se non viene fornita alcuna data, verrà utilizzata la data corrente. La risposta restituita sarà l'oggetto utente con l'aggiunta dei campi dell'esercizio. La risposta restituita da `POST /api/users/:_id/exercises` sarà l'oggetto dell'utente con un campo esercizi aggiutivo.
```js ```js
async (getUserInput) => { async (getUserInput) => {
@ -135,6 +217,9 @@ async (getUserInput) => {
if (addRes.ok) { if (addRes.ok) {
const actual = await addRes.json(); const actual = await addRes.json();
assert.deepEqual(actual, expected); assert.deepEqual(actual, expected);
assert.isString(actual.description);
assert.isNumber(actual.duration);
assert.isString(actual.date);
} else { } else {
throw new Error(`${addRes.status} ${addRes.statusText}`); throw new Error(`${addRes.status} ${addRes.statusText}`);
} }
@ -144,7 +229,7 @@ async (getUserInput) => {
}; };
``` ```
È possibile fare una richiesta `GET` a `/api/users/:_id/logs` per recuperare il log completo degli esercizi di qualsiasi utente. La risposta restituita sarà l'oggetto utente con un array `log` di tutti gli esercizi aggiunti. Ogni elemento di log ha le proprietà `description`, `duration` e `date`. Puoi fare una richiesta `GET` a `/api/users/:_id/logs` per recuperare l'intera storia degli esercizi di ogni utente.
```js ```js
async (getUserInput) => { async (getUserInput) => {
@ -170,13 +255,10 @@ async (getUserInput) => {
}); });
if (addRes.ok) { if (addRes.ok) {
const logRes = await fetch(url + `/api/users/${_id}/logs`); const logRes = await fetch(url + `/api/users/${_id}/logs`);
if (logRes.ok) { assert.isTrue(logRes.ok);
const { log } = await logRes.json(); if(!logRes.ok) {
assert.isArray(log); throw new Error(`${logRes.status} ${logRes.statusText}`)
assert.equal(1, log.length); };
} else {
throw new Error(`${logRes.status} ${logRes.statusText}`);
}
} else { } else {
throw new Error(`${addRes.status} ${addRes.statusText}`); throw new Error(`${addRes.status} ${addRes.statusText}`);
} }
@ -186,7 +268,7 @@ async (getUserInput) => {
}; };
``` ```
Una richiesta al log di un utente (`/api/users/:_id/logs`) restituisce un oggetto con una proprietà `count` che rappresenta il numero di esercizi restituiti. Una richiesta della storia degli esercizi `GET /api/users/:_id/logs` restituisce un oggetto con una proprietà `count` che rappresenta il numero degli esercizi che appartengono a quell'utente.
```js ```js
async (getUserInput) => { async (getUserInput) => {
@ -227,7 +309,239 @@ async (getUserInput) => {
}; };
``` ```
È possibile aggiungere parametri `from`, `to` e`limit` alla richiesta `/api/users/:_id/logs` per ricevere parte del log di ogni utente. `from` e `to` sono date nel formato `yyyy-mm-dd`. `limit` è un numero intero che indica quanti log devono essere restituiti. Una richiesta `GET` a `/api/users/:id/logs` restituisce un oggetto utente con un arraa `log` di tutti gli esercizi aggiunti.
```js
async(getUserInput) => {
const url = getUserInput('url');
const res = await fetch(url + '/api/users', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: `username=fcc_test_${Date.now()}`.substr(0, 29)
})
if(res.ok){
const {_id, username} = await res.json();
const expected = {
username,
description: 'test',
duration: 60,
_id,
date: new Date().toDateString()
};
const addRes = await fetch(url + `/api/users/${_id}/exercises`, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `description=${expected.description}&duration=${expected.duration}`
});
if(addRes.ok){
const logRes = await fetch(url + `/api/users/${_id}/logs`);
if(logRes.ok) {
const {log} = await logRes.json();
assert.isArray(log);
assert.equal(1, log.length);
} else {
throw new Error(`${logRes.status} ${logRes.statusText}`);
}
} else {
throw new Error(`${addRes.status} ${addRes.statusText}`);
};
} else {
throw new Error(`${res.status} ${res.statusText}`)
};
};
```
Ogni elemento nell'array `log` restituito da `GET /api/users/:id/logs` è un oggetto che dovrebbe avere proprietà `description`, `duration`, e `date`.
```js
async(getUserInput) => {
const url = getUserInput('url');
const res = await fetch(url + `/api/users`, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: `username=fcc_test_${Date.now()}`.substr(0, 29)
});
if(res.ok) {
const {_id, username} = await res.json();
const expected = {
username,
description: 'test',
duration: 60,
_id,
date: new Date().toDateString()
};
const addRes = await fetch(url + `/api/users/${_id}/exercises`, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `description=${expected.description}&duration=${expected.duration}`
});
if(addRes.ok) {
const logRes = await fetch(url + `/api/users/${_id}/logs`);
if(logRes.ok) {
const {log} = await logRes.json();
const exercise = log[0];
assert.exists(exercise);
assert.exists(exercise.description);
assert.exists(exercise.duration);
assert.exists(exercise.date);
} else {
throw new Error(`${logRes.status} ${logRes.statusText}`);
};
} else {
throw new Error(`${addRes.status} ${addRes.statusText}`);
};
} else {
throw new Error(`${res.status} ${res.statusText}`)
};
};
```
La proprietà `description` di ogni oggetto nell'array `log` restituito da `GET /api/users/:id/logs` dovrebbe essere una stringa.
```js
async(getUserInput) => {
const url = getUserInput('url');
const res = await fetch(url + '/api/users/', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `username=fcc_test_${Date.now()}`.substr(0,29)
});
if(res.ok) {
const {_id, username} = await res.json();
const expected = {
username,
description: 'test',
duration: 60,
_id,
date: new Date().toDateString()
};
const addRes = await fetch(url + `/api/users/${_id}/exercises`, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `description=${expected.description}&duration=${expected.duration}`
});
if(addRes.ok) {
const logRes = await fetch(url + `/api/users/${_id}/logs`);
if(logRes.ok){
const {log} = await logRes.json();
const exercise = log[0];
assert.isString(exercise.description);
assert.equal(exercise.description, expected.description);
} else {
throw new Error(`${logRes.status} ${logRes.statusText}`);
}
} else {
throw new Error(`${addRes.status} ${addRes.statusText}`);
};
} else {
throw new Error(`${res.status} ${res.statusText}`);
};
};
```
La proprietà `duration` di ogni oggetto nell'array `log` restituito da `GET /api/users/:id/logs` dovrebbe essere un numero.
```js
async(getUserInput) => {
const url = getUserInput('url');
const res = await fetch(url + '/api/users/', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `username=fcc_test_${Date.now()}`.substr(0,29)
});
if(res.ok) {
const {_id, username} = await res.json();
const expected = {
username,
description: 'test',
duration: 60,
_id,
date: new Date().toDateString()
};
const addRes = await fetch(url + `/api/users/${_id}/exercises`, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `description=${expected.description}&duration=${expected.duration}`
});
if(addRes.ok) {
const logRes = await fetch(url + `/api/users/${_id}/logs`);
if(logRes.ok){
const {log} = await logRes.json();
const exercise = log[0];
assert.isNumber(exercise.duration);
assert.equal(exercise.duration, expected.duration);
} else {
throw new Error(`${logRes.status} ${logRes.statusText}`);
}
} else {
throw new Error(`${addRes.status} ${addRes.statusText}`);
};
} else {
throw new Error(`${res.status} ${res.statusText}`);
};
};
```
La proprietà `date` di ogni oggetto nell'array `log` restituito da `GET /api/users/:id/logs` dovrebbe essere una stringa. Usa il formato `dateString` dell'API `Date`.
```js
async(getUserInput) => {
const url = getUserInput('url');
const res = await fetch(url + '/api/users/', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `username=fcc_test_${Date.now()}`.substr(0,29)
});
if(res.ok) {
const {_id, username} = await res.json();
const expected = {
username,
description: 'test',
duration: 60,
_id,
date: new Date().toDateString()
};
const addRes = await fetch(url + `/api/users/${_id}/exercises`, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `description=${expected.description}&duration=${expected.duration}`
});
if(addRes.ok) {
const logRes = await fetch(url + `/api/users/${_id}/logs`);
if(logRes.ok){
const {log} = await logRes.json();
const exercise = log[0];
assert.isString(exercise.date);
assert.equal(exercise.date, expected.date);
} else {
throw new Error(`${logRes.status} ${logRes.statusText}`);
}
} else {
throw new Error(`${addRes.status} ${addRes.statusText}`);
};
} else {
throw new Error(`${res.status} ${res.statusText}`);
};
};
```
È possibile aggiungere parametri `from`, `to` e`limit` alla richiesta `GET /api/users/:_id/logs` per ricevere parte del log di ogni utente. `from` e `to` sono date nel formato `yyyy-mm-dd`. `limit` è un numero intero che indica quanti log devono essere restituiti.
```js ```js
async (getUserInput) => { async (getUserInput) => {

View File

@ -11,8 +11,6 @@ dashedName: move-a-relatively-positioned-element-with-css-offsets
As propriedades de deslocamento CSS `top` ou `bottom` e `left` ou `right` informam ao navegador o quanto deslocar um elemento em relação onde ele ficaria no fluxo normal do documento. Ao deslocar um elemento para um determinado ponto, você move o elemento para o lado oposto da propriedade (de deslocamento) usada. Como você viu no desafio anterior, usar a propriedade de deslocamento `top` moveu o elemento `h2` para baixo. Da mesma forma, usar a propriedade de deslocamento `left` move um item para a direita. As propriedades de deslocamento CSS `top` ou `bottom` e `left` ou `right` informam ao navegador o quanto deslocar um elemento em relação onde ele ficaria no fluxo normal do documento. Ao deslocar um elemento para um determinado ponto, você move o elemento para o lado oposto da propriedade (de deslocamento) usada. Como você viu no desafio anterior, usar a propriedade de deslocamento `top` moveu o elemento `h2` para baixo. Da mesma forma, usar a propriedade de deslocamento `left` move um item para a direita.
<img src='https://cdn-media-1.freecodecamp.org/imgr/eWWi3gZ.gif' alt='' />
# --instructions-- # --instructions--
Use as propriedade de deslocamento CSS para mover o `h2` 15 pixels para a direita e 10 pixels para cima. Use as propriedade de deslocamento CSS para mover o `h2` 15 pixels para a direita e 10 pixels para cima.

View File

@ -1,6 +1,6 @@
--- ---
id: 5a24c314108439a4d4036185 id: 5a24c314108439a4d4036185
title: Use && for a More Concise Conditional title: Usar && para uma forma mais concisa do condicional
challengeType: 6 challengeType: 6
forumTopicId: 301413 forumTopicId: 301413
dashedName: use--for-a-more-concise-conditional dashedName: use--for-a-more-concise-conditional

View File

@ -47,7 +47,7 @@ Log:
{ {
username: "fcc_test", username: "fcc_test",
count: 1, count: 1,
_id: "5fd01a41c5b5cf05d080502f", _id: "5fb5853f734231456ccb3b05",
log: [{ log: [{
description: "test", description: "test",
duration: 60, duration: 60,
@ -71,7 +71,24 @@ Você deve fornecer seu próprio projeto, não o exemplo de URL.
}; };
``` ```
Você pode fazer a solicitação de `POST` para `/api/users` com dados do formulário `username` para criar um novo usuário. A resposta retornada será um objeto com as propriedades `username` e `_id`. Você pode fazer a solicitação de `POST` para `/api/users` com dados do formulário `username` para criar um novo usuário.
```js
async (getUserInput) => {
const url = getUserInput('url');
const res = await fetch(url + '/api/users', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `username=fcc_test_${Date.now()}`.substr(0, 29)
});
assert.isTrue(res.ok);
if(!res.ok) {
throw new Error(`${res.status} ${res.statusText}`)
};
};
```
A resposta retornada de `POST /api/users` com dados do formulário `username` será um objeto com as propriedades `username` e `_id`.
```js ```js
async (getUserInput) => { async (getUserInput) => {
@ -91,24 +108,89 @@ async (getUserInput) => {
}; };
``` ```
Você pode fazer uma solicitação de `GET` a `/api/users` para obter um array de todos os usuários. Cada elemento no array é um objeto que contém `username` e `_id` dos usuários. Você pode fazer uma solicitação de `GET` a `/api/users` para obter uma lista com todos os usuários.
```js
async(getUserInput) => {
const url = getUserInput('url');
const res = await fetch(url + '/api/users');
assert.isTrue(res.ok);
if(!res.ok) {
throw new Error(`${res.status} ${res.statusText}`)
};
};
```
A solicitação de `GET` a `/api/users` retorna um array.
```js ```js
async(getUserInput) => { async(getUserInput) => {
const url = getUserInput('url'); const url = getUserInput('url');
const res = await fetch(url + '/api/users'); const res = await fetch(url + '/api/users');
if(res.ok){ if(res.ok){
const data = await res.json(); const users = await res.json();
assert.isArray(data); assert.isArray(users);
assert.isString(data[0].username); } else {
assert.isString(data[0]._id); throw new Error(`${res.status} ${res.statusText}`);
};
};
```
Cada elemento do array retornado de `GET /api/users` é um objeto literal que contém o `username` e a `_id` do usuário.
```js
async(getUserInput) => {
const url = getUserInput('url');
const res = await fetch(url + '/api/users');
if(res.ok){
const users = await res.json();
const user = users[0];
assert.exists(user);
assert.exists(user.username);
assert.exists(user._id);
assert.isString(user.username);
assert.isString(user._id);
} else {
throw new Error(`${res.status} ${res.statusText}`);
};
};
```
Você pode fazer a solicitação de `POST` para `/api/users/:_id/exercises` com os dados do formulário `description`, `duration` e, como opção, `date`. Se nenhuma data for fornecida, a data atual será utilizada.
```js
async (getUserInput) => {
const url = getUserInput('url');
const res = await fetch(url + '/api/users', {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `username=fcc_test_${Date.now()}`.substr(0, 29)
});
if (res.ok) {
const { _id, username } = await res.json();
const expected = {
username,
description: 'test',
duration: 60,
_id,
date: 'Mon Jan 01 1990'
};
const addRes = await fetch(url + `/api/users/${_id}/exercises`, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `description=${expected.description}&duration=${expected.duration}&date=1990-01-01`
});
assert.isTrue(addRes.ok);
if(!addRes.ok) {
throw new Error(`${addRes.status} ${addRes.statusText}`)
};
} else { } else {
throw new Error(`${res.status} ${res.statusText}`); throw new Error(`${res.status} ${res.statusText}`);
} }
}; };
``` ```
Você pode fazer a solicitação de `POST` para `/api/users/:_id/exercises` com os dados do formulário `description`, `duration` e, como opção, `date`. Se nenhuma data for fornecida, a data atual será utilizada. A resposta retornada será o objeto do usuário com os campos de exercício adicionados. A resposta retornada de `POST /api/users/:_id/exercises` será o objeto do usuário com os campos de exercício adicionados.
```js ```js
async (getUserInput) => { async (getUserInput) => {
@ -135,6 +217,9 @@ async (getUserInput) => {
if (addRes.ok) { if (addRes.ok) {
const actual = await addRes.json(); const actual = await addRes.json();
assert.deepEqual(actual, expected); assert.deepEqual(actual, expected);
assert.isString(actual.description);
assert.isNumber(actual.duration);
assert.isString(actual.date);
} else { } else {
throw new Error(`${addRes.status} ${addRes.statusText}`); throw new Error(`${addRes.status} ${addRes.statusText}`);
} }
@ -144,7 +229,7 @@ async (getUserInput) => {
}; };
``` ```
Você pode fazer uma solicitação de `GET` a `/api/users/:_id/logs` para obter um registro completo dos exercícios de qualquer usuário. A resposta retornada será o objeto de usuário com um array de `log` de todos os exercícios adicionados. Cada item do registro (log) terá as propriedades `description`, `duration` e `date`. Você pode fazer uma solicitação de `GET` a `/api/users/:_id/logs` para obter um registro completo dos exercícios de qualquer usuário.
```js ```js
async (getUserInput) => { async (getUserInput) => {
@ -170,13 +255,10 @@ async (getUserInput) => {
}); });
if (addRes.ok) { if (addRes.ok) {
const logRes = await fetch(url + `/api/users/${_id}/logs`); const logRes = await fetch(url + `/api/users/${_id}/logs`);
if (logRes.ok) { assert.isTrue(logRes.ok);
const { log } = await logRes.json(); if(!logRes.ok) {
assert.isArray(log); throw new Error(`${logRes.status} ${logRes.statusText}`)
assert.equal(1, log.length); };
} else {
throw new Error(`${logRes.status} ${logRes.statusText}`);
}
} else { } else {
throw new Error(`${addRes.status} ${addRes.statusText}`); throw new Error(`${addRes.status} ${addRes.statusText}`);
} }
@ -186,7 +268,7 @@ async (getUserInput) => {
}; };
``` ```
Uma solicitação para o registro (log) de um usuário (`/api/users/:_id/logs`) retornará um objeto com uma propriedade `count`, que representa o número de exercícios retornados. Uma solicitação para o registro (log) de um usuário (`GET /api/users/:_id/logs`) retornará um objeto com uma propriedade `count`, que representa o número de exercícios que pertencem àquele usuário.
```js ```js
async (getUserInput) => { async (getUserInput) => {
@ -227,7 +309,239 @@ async (getUserInput) => {
}; };
``` ```
Você pode adicionar os parâmetros `from`, `to` e `limit` a uma solicitação para `/api/users/:_id/logs` para recuperar parte do registro de qualquer usuário. `from` e `to` são datas no formato `yyyy-mm-dd`. `limit` é um número inteiro de quantos registros devem ser enviados de volta. Uma solicitação de `GET` a `/api/users/:id/logs` retornará o objeto do usuário com um array `log` de todos os exercícios adicionados.
```js
async(getUserInput) => {
const url = getUserInput('url');
const res = await fetch(url + '/api/users', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: `username=fcc_test_${Date.now()}`.substr(0, 29)
})
if(res.ok){
const {_id, username} = await res.json();
const expected = {
username,
description: 'test',
duration: 60,
_id,
date: new Date().toDateString()
};
const addRes = await fetch(url + `/api/users/${_id}/exercises`, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `description=${expected.description}&duration=${expected.duration}`
});
if(addRes.ok){
const logRes = await fetch(url + `/api/users/${_id}/logs`);
if(logRes.ok) {
const {log} = await logRes.json();
assert.isArray(log);
assert.equal(1, log.length);
} else {
throw new Error(`${logRes.status} ${logRes.statusText}`);
}
} else {
throw new Error(`${addRes.status} ${addRes.statusText}`);
};
} else {
throw new Error(`${res.status} ${res.statusText}`)
};
};
```
Cada item no array `log` que é retornado de `GET /api/users/:id/logs` é um objeto que deve ter as propriedades `description`, uma `duration` e uma `date`.
```js
async(getUserInput) => {
const url = getUserInput('url');
const res = await fetch(url + `/api/users`, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: `username=fcc_test_${Date.now()}`.substr(0, 29)
});
if(res.ok) {
const {_id, username} = await res.json();
const expected = {
username,
description: 'test',
duration: 60,
_id,
date: new Date().toDateString()
};
const addRes = await fetch(url + `/api/users/${_id}/exercises`, {
method: 'POST',
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
body: `description=${expected.description}&duration=${expected.duration}`
});
if(addRes.ok) {
const logRes = await fetch(url + `/api/users/${_id}/logs`);
if(logRes.ok) {
const {log} = await logRes.json();
const exercise = log[0];
assert.exists(exercise);
assert.exists(exercise.description);
assert.exists(exercise.duration);
assert.exists(exercise.date);
} else {
throw new Error(`${logRes.status} ${logRes.statusText}`);
};
} else {
throw new Error(`${addRes.status} ${addRes.statusText}`);
};
} else {
throw new Error(`${res.status} ${res.statusText}`)
};
};
```
A propriedade `description` de qualquer objeto no array `log` retornada de `GET /api/users/:id/logs` deve ser uma string.
```js
async(getUserInput) => {
const url = getUserInput('url');
const res = await fetch(url + '/api/users/', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `username=fcc_test_${Date.now()}`.substr(0,29)
});
if(res.ok) {
const {_id, username} = await res.json();
const expected = {
username,
description: 'test',
duration: 60,
_id,
date: new Date().toDateString()
};
const addRes = await fetch(url + `/api/users/${_id}/exercises`, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `description=${expected.description}&duration=${expected.duration}`
});
if(addRes.ok) {
const logRes = await fetch(url + `/api/users/${_id}/logs`);
if(logRes.ok){
const {log} = await logRes.json();
const exercise = log[0];
assert.isString(exercise.description);
assert.equal(exercise.description, expected.description);
} else {
throw new Error(`${logRes.status} ${logRes.statusText}`);
}
} else {
throw new Error(`${addRes.status} ${addRes.statusText}`);
};
} else {
throw new Error(`${res.status} ${res.statusText}`);
};
};
```
A propriedade `duration` de qualquer objeto no array `log` que é retornada de `GET /api/users/:id/logs` deve ser um número.
```js
async(getUserInput) => {
const url = getUserInput('url');
const res = await fetch(url + '/api/users/', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `username=fcc_test_${Date.now()}`.substr(0,29)
});
if(res.ok) {
const {_id, username} = await res.json();
const expected = {
username,
description: 'test',
duration: 60,
_id,
date: new Date().toDateString()
};
const addRes = await fetch(url + `/api/users/${_id}/exercises`, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `description=${expected.description}&duration=${expected.duration}`
});
if(addRes.ok) {
const logRes = await fetch(url + `/api/users/${_id}/logs`);
if(logRes.ok){
const {log} = await logRes.json();
const exercise = log[0];
assert.isNumber(exercise.duration);
assert.equal(exercise.duration, expected.duration);
} else {
throw new Error(`${logRes.status} ${logRes.statusText}`);
}
} else {
throw new Error(`${addRes.status} ${addRes.statusText}`);
};
} else {
throw new Error(`${res.status} ${res.statusText}`);
};
};
```
A propriedade `date` de qualquer objeto no array `log` retornada de `GET /api/users/:id/logs` deve ser uma string. Use o formato `dateString` da API `Date`.
```js
async(getUserInput) => {
const url = getUserInput('url');
const res = await fetch(url + '/api/users/', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `username=fcc_test_${Date.now()}`.substr(0,29)
});
if(res.ok) {
const {_id, username} = await res.json();
const expected = {
username,
description: 'test',
duration: 60,
_id,
date: new Date().toDateString()
};
const addRes = await fetch(url + `/api/users/${_id}/exercises`, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: `description=${expected.description}&duration=${expected.duration}`
});
if(addRes.ok) {
const logRes = await fetch(url + `/api/users/${_id}/logs`);
if(logRes.ok){
const {log} = await logRes.json();
const exercise = log[0];
assert.isString(exercise.date);
assert.equal(exercise.date, expected.date);
} else {
throw new Error(`${logRes.status} ${logRes.statusText}`);
}
} else {
throw new Error(`${addRes.status} ${addRes.statusText}`);
};
} else {
throw new Error(`${res.status} ${res.statusText}`);
};
};
```
Você pode adicionar os parâmetros `from`, `to` e `limit` a uma solicitação para `GET /api/users/:_id/logs` para recuperar parte do registro de qualquer usuário. `from` e `to` são datas no formato `yyyy-mm-dd`. `limit` é um número inteiro de quantos registros devem ser enviados de volta.
```js ```js
async (getUserInput) => { async (getUserInput) => {