ynov-toulouse-b3-info-live-score-api
v1.0.4
Published
```npm install ynov-toulouse-b3-info-live-score-api```
Readme
Live Score API
Install
npm install ynov-toulouse-b3-info-live-score-api
Usage
Asynchronous API
Import
import { liveScoreRepositoryAsync } from 'ynov-toulouse-b3-info-live-score-api';Count
liveScoreRepositoryAsync.count()
.then(count => console.log(count))
.catch(error => console.error(error));Find all
liveScoreRepositoryAsync.findAll()
.then(items => console.log(items))
.catch(error => console.error(error));Find by page
const pageIndex = 0;
const pageSize = 20;
liveScoreRepositoryAsync.findByPage(pageIndex, pageSize)
.then(items => console.log(items))
.catch(error => console.error(error));Find by id
const id = 120;
liveScoreRepositoryAsync.findById(id)
.then(item => console.log(item))
.catch(error => console.error(error));Create
const item = {
date: '2017-08-03T20:45:00.000+01:00',
homeTeamName: 'Barcelona',
awayTeamName: 'Paris Saint-Germain',
homeTeamScore: 6,
awayTeamScore: 1,
};
liveScoreRepositoryAsync.create(item)
.then(items => console.log(items))
.catch(error => console.error(error));Update
const id = 121;
const partialItem = {
homeTeamName: 'FCB',
awayTeamName: 'PSG',
};
liveScoreRepositoryAsync.update(id, partialItem)
.then(items => console.log(items))
.catch(error => console.error(error));Replace
const id = 121;
const item = {
date: '2017-08-03T20:45:00.000+01:00',
homeTeamName: 'Barcelona',
awayTeamName: 'Paris Saint-Germain',
homeTeamScore: 6,
awayTeamScore: 1,
};
liveScoreRepositoryAsync.replace(id, item)
.then(items => console.log(items))
.catch(error => console.error(error));Remove
const id = 121;
liveScoreRepositoryAsync.remove(id)
.then(() => console.log('removed'))
.catch(error => console.error(error));Synchronous API
import { liveScoreRepositorySync } from 'ynov-toulouse-b3-info-live-score-api';Count
try {
const count = liveScoreRepositorySync.count();
console.log(count);
} catch (error) {
console.error(error);
}Find all
try {
const items = liveScoreRepositorySync.findAll();
console.log(items);
} catch (error) {
console.error(error);
}Find by page
const pageIndex = 0;
const pageSize = 20;
try {
const items = liveScoreRepositorySync.findByPage(pageIndex, pageSize);
console.log(items);
} catch (error) {
console.error(error);
}Find by id
const id = 120;
try {
const item = liveScoreRepositorySync.findById(id);
console.log(item);
} catch (error) {
console.error(error);
}Create
const item = {
date: '2017-08-03T20:45:00.000+01:00',
homeTeamName: 'Barcelona',
awayTeamName: 'Paris Saint-Germain',
homeTeamScore: 6,
awayTeamScore: 1,
};
try {
const createdItem = liveScoreRepositorySync.create(item);
console.log(createdItem);
} catch (error) {
console.error(error);
}Update
const id = 121;
const partialItem = {
homeTeamName: 'FCB',
awayTeamName: 'PSG',
};
try {
const updatedItem = liveScoreRepositorySync.update(id, partialItem);
console.log(updatedItem);
} catch (error) {
console.error(error);
}Replace
const id = 121;
const item = {
date: '2017-08-03T20:45:00.000+01:00',
homeTeamName: 'Barcelona',
awayTeamName: 'Paris Saint-Germain',
homeTeamScore: 6,
awayTeamScore: 1,
};
try {
const updatedItem = liveScoreRepositorySync.replace(id, item)
console.log(updatedItem);
} catch (error) {
console.error(error);
}Remove
const id = 121;
try {
liveScoreRepositorySync.remove(id)
console.log('removed');
} catch (error) {
console.error(error);
}Commands
Run
npm run start
Run development
npm run start/dev
Test
npm run test
Test development
npm run test:watch
| Description | Request method | Request route | Request query params | Request route params | Request body | Response nominal body | Response nominal headers | Response nominal status | Response error body | Response error status |
|--------------------------------|----------------|--------------------|--------------------------------------------------------------------------------------------------------------|---------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------|-------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------|
| Fetch a page of items | GET | /live-scores | pageIndex: natural integer (0, 1, 2, ...)pageSize: positive integer (1, 2, 3, ...) | | | [{ id: 1, date: '2017-08-03T20:45:00.000+01:00', homeTeamName: 'FCB', awayTeamName: 'PSG', homeTeamScore: 6, awayTeamScore: 1 }] | x-total-count: items total count in database: natural integer (0, 1, 2, ...) | 200 | { status: 400, code: 'BAD_PARAMETER_FORMAT', detail: 'pageIndex should be a natural integer' }{ status: 400, code: 'BAD_PARAMETER_FORMAT', detail: 'pageSize should be a positive integer' } | 400 |
| Fetch an item | GET | /live-scores/:id | | id: positive integer (1, 2, 3, ...) | | { id: 1, date: '2017-08-03T20:45:00.000+01:00', homeTeamName: 'FCB', awayTeamName: 'PSG', homeTeamScore: 6, awayTeamScore: 1 } | | 200 | { status: 400, code: 'BAD_PARAMETER_FORMAT', detail: 'id should be a positive integer' }{ status: 404, code: 'RESOURCE_ID_NOT_FOUND', detail: 'no entity found with given id' } | 400404 |
| Create an item | POST | /live-scores | | | { date: '2017-08-03T20:45:00.000+01:00', homeTeamName: 'FCB', awayTeamName: 'PSG', homeTeamScore: 6, awayTeamScore: 1 } | { id: 1, date: '2017-08-03T20:45:00.000+01:00', homeTeamName: 'FCB', awayTeamName: 'PSG', homeTeamScore: 6, awayTeamScore: 1 } | | 201 | { status: 400, code: 'BAD_RESOURCE_FORMAT', detail: '[attribute] should be a [number/integer/string/ISO date/...]' } | 400 |
| Patch an item (partial update) | PATCH | /live-scores/:id | | id: positive integer (1, 2, 3, ...) | { date: '2017-08-03T20:45:00.000+01:00', homeTeamName: 'FCB', awayTeamName: 'PSG', homeTeamScore: 6, awayTeamScore: 1 } | { id: 1, date: '2017-08-03T20:45:00.000+01:00', homeTeamName: 'FCB', awayTeamName: 'PSG', homeTeamScore: 6, awayTeamScore: 1 } | | 200 | { status: 400, code: 'BAD_PARAMETER_FORMAT', detail: 'id should be a positive integer' }{ status: 404, code: 'RESOURCE_ID_NOT_FOUND', detail: 'no entity found with given id' }{ status: 400, code: 'BAD_RESOURCE_FORMAT', detail: '[attribute] should be a [number/integer/string/ISO date/...]' } | 400404 |
| Replace an item (full update) | PUT | /live-scores/:id | | id: positive integer (1, 2, 3, ...) | { date: '2017-08-03T20:45:00.000+01:00', homeTeamName: 'FCB', awayTeamName: 'PSG', homeTeamScore: 6, awayTeamScore: 1 } | { id: 1, date: '2017-08-03T20:45:00.000+01:00', homeTeamName: 'FCB', awayTeamName: 'PSG', homeTeamScore: 6, awayTeamScore: 1 } | | 200 | { status: 400, code: 'BAD_PARAMETER_FORMAT', detail: 'id should be a positive integer' }{ status: 404, code: 'RESOURCE_ID_NOT_FOUND', detail: 'no entity found with given id' }{ status: 400, code: 'BAD_RESOURCE_FORMAT', detail: '[attribute] should be a [number/integer/string/ISO date/...]' } | 400404 |
| Remove an item | DELETE | /live-scores/:id | | id: positive integer (1, 2, 3, ...) | | { id: 1, date: '2017-08-03T20:45:00.000+01:00', homeTeamName: 'FCB', awayTeamName: 'PSG', homeTeamScore: 6, awayTeamScore: 1 } | | 204 | { status: 400, code: 'BAD_PARAMETER_FORMAT', detail: 'id should be a positive integer' }{ status: 404, code: 'RESOURCE_ID_NOT_FOUND', detail: 'no entity found with given id' } | 400404 |
