style: formater sources et scripts (prettier)

This commit is contained in:
devcodetools committed 2026-09-21 17:55:34 +02:00
1 parent 01337ef480
commit 77ac6e0e21
8 files changed
+31 -18

No files matched your search

+5 -4
View File
@@ -33,7 +33,7 @@ db.cards.insertMany([
{ {
c_id: '10000000-0000-4000-8000-000000000004', c_id: '10000000-0000-4000-8000-000000000004',
question: 'À quoi sert le type unknown ?', 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', theme: 'typescript',
tags: ['types'], tags: ['types'],
createdAt: new Date(), createdAt: new Date(),
@@ -42,7 +42,8 @@ db.cards.insertMany([
{ {
c_id: '10000000-0000-4000-8000-000000000005', c_id: '10000000-0000-4000-8000-000000000005',
question: "Qu'est-ce qu'un hook React ?", 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', theme: 'react',
tags: ['hooks', 'composants'], tags: ['hooks', 'composants'],
createdAt: new Date(), createdAt: new Date(),
@@ -78,7 +79,7 @@ db.cards.insertMany([
{ {
c_id: '10000000-0000-4000-8000-000000000009', c_id: '10000000-0000-4000-8000-000000000009',
question: "Qu'est-ce qu'un volume Docker ?", 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', theme: 'docker',
tags: ['stockage'], tags: ['stockage'],
createdAt: new Date(), createdAt: new Date(),
@@ -93,4 +94,4 @@ db.cards.insertMany([
createdAt: new Date(), createdAt: new Date(),
updatedAt: new Date(), updatedAt: new Date(),
}, },
]) ])
+1 -1
View File
@@ -29,4 +29,4 @@ describe('getCardRepository', () => {
process.env.DB_IMPL = 'mongo' process.env.DB_IMPL = 'mongo'
expect(getCardRepository()).toBeInstanceOf(MongoCardRepository) expect(getCardRepository()).toBeInstanceOf(MongoCardRepository)
}) })
}) })
+1 -1
View File
@@ -10,4 +10,4 @@ export function getCardRepository(): CardRepository {
return new MongoCardRepository() return new MongoCardRepository()
} }
return new MysqlCardRepository() return new MysqlCardRepository()
} }
+1 -1
View File
@@ -9,4 +9,4 @@ export interface CardRepository {
findRandom(): Promise<Card | null> findRandom(): Promise<Card | null>
findRandomByTheme(theme: string): Promise<Card | null> findRandomByTheme(theme: string): Promise<Card | null>
findThemes(): Promise<string[]> findThemes(): Promise<string[]>
} }
+1 -1
View File
@@ -13,4 +13,4 @@ export interface CardInput {
response: string response: string
theme: string theme: string
tags?: string[] tags?: string[]
} }
@@ -154,4 +154,4 @@ describe('MysqlCardRepository', () => {
query.mockResolvedValueOnce([[{ theme: 'docker' }, { theme: 'javascript' }]]) query.mockResolvedValueOnce([[{ theme: 'docker' }, { theme: 'javascript' }]])
await expect(repo.findThemes()).resolves.toEqual(['docker', 'javascript']) await expect(repo.findThemes()).resolves.toEqual(['docker', 'javascript'])
}) })
}) })
+20 -8
View File
@@ -47,17 +47,25 @@ export class MysqlCardRepository implements CardRepository {
} }
async findById(id: string): Promise<Card | null> { async findById(id: string): Promise<Card | null> {
const [rows] = await this.pool.query<CardRow[]>(`SELECT ${FIELDS.join(', ')} FROM cards WHERE id = ?`, [id]) const [rows] = await this.pool.query<CardRow[]>(
`SELECT ${FIELDS.join(', ')} FROM cards WHERE id = ?`,
[id],
)
return rows[0] ? this.mapRow(rows[0]) : null return rows[0] ? this.mapRow(rows[0]) : null
} }
async create(input: CardInput): Promise<Card> { async create(input: CardInput): Promise<Card> {
const id = crypto.randomUUID() const id = crypto.randomUUID()
const now = new Date() const now = new Date()
await this.pool.query( await this.pool.query(`INSERT INTO cards (${FIELDS.join(', ')}) VALUES (?, ?, ?, ?, ?, ?, ?)`, [
`INSERT INTO cards (${FIELDS.join(', ')}) VALUES (?, ?, ?, ?, ?, ?, ?)`, id,
[id, input.question, input.response, input.theme, JSON.stringify(input.tags ?? []), now, now], input.question,
) input.response,
input.theme,
JSON.stringify(input.tags ?? []),
now,
now,
])
return { return {
id, id,
question: input.question, question: input.question,
@@ -104,7 +112,9 @@ export class MysqlCardRepository implements CardRepository {
} }
async findRandom(): Promise<Card | null> { async findRandom(): Promise<Card | null> {
const [rows] = await this.pool.query<CardRow[]>(`SELECT ${FIELDS.join(', ')} FROM cards ORDER BY RAND() LIMIT 1`) const [rows] = await this.pool.query<CardRow[]>(
`SELECT ${FIELDS.join(', ')} FROM cards ORDER BY RAND() LIMIT 1`,
)
return rows[0] ? this.mapRow(rows[0]) : null return rows[0] ? this.mapRow(rows[0]) : null
} }
@@ -117,7 +127,9 @@ export class MysqlCardRepository implements CardRepository {
} }
async findThemes(): Promise<string[]> { async findThemes(): Promise<string[]> {
const [rows] = await this.pool.query<RowDataPacket[]>('SELECT DISTINCT theme FROM cards ORDER BY theme') const [rows] = await this.pool.query<RowDataPacket[]>(
'SELECT DISTINCT theme FROM cards ORDER BY theme',
)
return rows.map((row) => row.theme as string) return rows.map((row) => row.theme as string)
} }
} }
+1 -1
View File
@@ -18,4 +18,4 @@ if (typeof window !== 'undefined') {
dispatchEvent: () => false, dispatchEvent: () => false,
}), }),
}) })
} }