diff --git a/docker/init/mongo/init.js b/docker/init/mongo/init.js index dcc0b31..785b1f0 100644 --- a/docker/init/mongo/init.js +++ b/docker/init/mongo/init.js @@ -33,7 +33,7 @@ db.cards.insertMany([ { c_id: '10000000-0000-4000-8000-000000000004', question: 'À quoi sert le type unknown ?', - response: "Il représente une valeur inconnue qui exige un contrôle de type avant usage.", + response: 'Il représente une valeur inconnue qui exige un contrôle de type avant usage.', theme: 'typescript', tags: ['types'], createdAt: new Date(), @@ -42,7 +42,8 @@ db.cards.insertMany([ { c_id: '10000000-0000-4000-8000-000000000005', question: "Qu'est-ce qu'un hook React ?", - response: "Une fonction qui permet de brancher l'état et le cycle de vie dans un composant fonctionnel.", + response: + "Une fonction qui permet de brancher l'état et le cycle de vie dans un composant fonctionnel.", theme: 'react', tags: ['hooks', 'composants'], createdAt: new Date(), @@ -78,7 +79,7 @@ db.cards.insertMany([ { c_id: '10000000-0000-4000-8000-000000000009', question: "Qu'est-ce qu'un volume Docker ?", - response: "Un stockage persistant indépendant du cycle de vie du conteneur.", + response: 'Un stockage persistant indépendant du cycle de vie du conteneur.', theme: 'docker', tags: ['stockage'], createdAt: new Date(), @@ -93,4 +94,4 @@ db.cards.insertMany([ createdAt: new Date(), updatedAt: new Date(), }, -]) \ No newline at end of file +]) diff --git a/src/config/card-repository-factory.test.ts b/src/config/card-repository-factory.test.ts index 3119d0b..814603d 100644 --- a/src/config/card-repository-factory.test.ts +++ b/src/config/card-repository-factory.test.ts @@ -29,4 +29,4 @@ describe('getCardRepository', () => { process.env.DB_IMPL = 'mongo' expect(getCardRepository()).toBeInstanceOf(MongoCardRepository) }) -}) \ No newline at end of file +}) diff --git a/src/config/card-repository-factory.ts b/src/config/card-repository-factory.ts index 6b46566..564cd30 100644 --- a/src/config/card-repository-factory.ts +++ b/src/config/card-repository-factory.ts @@ -10,4 +10,4 @@ export function getCardRepository(): CardRepository { return new MongoCardRepository() } return new MysqlCardRepository() -} \ No newline at end of file +} diff --git a/src/domain/card-repository.ts b/src/domain/card-repository.ts index 0020cbd..bf9bb32 100644 --- a/src/domain/card-repository.ts +++ b/src/domain/card-repository.ts @@ -9,4 +9,4 @@ export interface CardRepository { findRandom(): Promise findRandomByTheme(theme: string): Promise findThemes(): Promise -} \ No newline at end of file +} diff --git a/src/domain/card.ts b/src/domain/card.ts index fc07206..654398d 100644 --- a/src/domain/card.ts +++ b/src/domain/card.ts @@ -13,4 +13,4 @@ export interface CardInput { response: string theme: string tags?: string[] -} \ No newline at end of file +} diff --git a/src/repositories/mysql-card-repository.test.ts b/src/repositories/mysql-card-repository.test.ts index 3867999..9b9b216 100644 --- a/src/repositories/mysql-card-repository.test.ts +++ b/src/repositories/mysql-card-repository.test.ts @@ -154,4 +154,4 @@ describe('MysqlCardRepository', () => { query.mockResolvedValueOnce([[{ theme: 'docker' }, { theme: 'javascript' }]]) await expect(repo.findThemes()).resolves.toEqual(['docker', 'javascript']) }) -}) \ No newline at end of file +}) diff --git a/src/repositories/mysql-card-repository.ts b/src/repositories/mysql-card-repository.ts index 8fb1498..524dbac 100644 --- a/src/repositories/mysql-card-repository.ts +++ b/src/repositories/mysql-card-repository.ts @@ -47,17 +47,25 @@ export class MysqlCardRepository implements CardRepository { } async findById(id: string): Promise { - const [rows] = await this.pool.query(`SELECT ${FIELDS.join(', ')} FROM cards WHERE id = ?`, [id]) + const [rows] = await this.pool.query( + `SELECT ${FIELDS.join(', ')} FROM cards WHERE id = ?`, + [id], + ) return rows[0] ? this.mapRow(rows[0]) : null } async create(input: CardInput): Promise { const id = crypto.randomUUID() const now = new Date() - await this.pool.query( - `INSERT INTO cards (${FIELDS.join(', ')}) VALUES (?, ?, ?, ?, ?, ?, ?)`, - [id, input.question, input.response, input.theme, JSON.stringify(input.tags ?? []), now, now], - ) + await this.pool.query(`INSERT INTO cards (${FIELDS.join(', ')}) VALUES (?, ?, ?, ?, ?, ?, ?)`, [ + id, + input.question, + input.response, + input.theme, + JSON.stringify(input.tags ?? []), + now, + now, + ]) return { id, question: input.question, @@ -104,7 +112,9 @@ export class MysqlCardRepository implements CardRepository { } async findRandom(): Promise { - const [rows] = await this.pool.query(`SELECT ${FIELDS.join(', ')} FROM cards ORDER BY RAND() LIMIT 1`) + const [rows] = await this.pool.query( + `SELECT ${FIELDS.join(', ')} FROM cards ORDER BY RAND() LIMIT 1`, + ) return rows[0] ? this.mapRow(rows[0]) : null } @@ -117,7 +127,9 @@ export class MysqlCardRepository implements CardRepository { } async findThemes(): Promise { - const [rows] = await this.pool.query('SELECT DISTINCT theme FROM cards ORDER BY theme') + const [rows] = await this.pool.query( + 'SELECT DISTINCT theme FROM cards ORDER BY theme', + ) return rows.map((row) => row.theme as string) } -} \ No newline at end of file +} diff --git a/src/test/setup.ts b/src/test/setup.ts index d2412e3..c9d8be0 100644 --- a/src/test/setup.ts +++ b/src/test/setup.ts @@ -18,4 +18,4 @@ if (typeof window !== 'undefined') { dispatchEvent: () => false, }), }) -} \ No newline at end of file +}