-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2df2e33
commit d5c15d4
Showing
21 changed files
with
489 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const defaultLanguage = "en" as const; | ||
|
||
export const supportedLanguages = ["it", "en"] as const; | ||
|
||
export type SupportedLanguages = (typeof supportedLanguages)[number]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,37 @@ | ||
import type {LocalizedFirestoreDocument} from "~/data/firestore/docs/model-document-mapper"; | ||
import {type FirestoreDataConverter, type QueryDocumentSnapshot, Timestamp} from "firebase-admin/firestore"; | ||
import { | ||
QueryDocumentSnapshot, | ||
Timestamp, | ||
type FirestoreDataConverter, | ||
} from "firebase-admin/firestore"; | ||
import type { FirestoreDocument } from "~/data/model-document-mapper"; | ||
localizedFieldFromFirestore, | ||
localizedFieldToFirestore | ||
} from "~/data/firestore/docs/converters/localization-converter.ts"; | ||
import omit from "~/data/firestore/docs/utils.ts"; | ||
|
||
export type TestModel = { | ||
id?: string; | ||
name: string; | ||
description?: string; | ||
lastUpdate: Date; | ||
}; | ||
|
||
export type TestDoc = FirestoreDocument<TestModel>; | ||
type TestDocLocalizedFields = "description"; | ||
|
||
export type TestDoc = LocalizedFirestoreDocument<TestModel, TestDocLocalizedFields> | ||
|
||
export const testConverter: FirestoreDataConverter<TestModel, TestDoc> = { | ||
toFirestore: (company: TestModel): TestDoc => { | ||
return { | ||
...company, | ||
lastUpdate: Timestamp.fromDate(company.lastUpdate), | ||
toFirestore: (model: TestModel): TestDoc => { | ||
const rest = omit(model, ["id", "description"]); | ||
const doc: TestDoc = { | ||
...rest, | ||
lastUpdate: Timestamp.fromDate(model.lastUpdate), | ||
}; | ||
return localizedFieldToFirestore(model, "en", ["description"], doc); | ||
}, | ||
fromFirestore: (snapshot: QueryDocumentSnapshot): TestModel => { | ||
const data = snapshot.data(); | ||
const model = localizedFieldFromFirestore<TestModel, TestDocLocalizedFields>(snapshot, "en", ["description"]); | ||
return { | ||
id: snapshot.id, | ||
...data, | ||
...model, | ||
lastUpdate: data.lastUpdate.toDate(), | ||
} as TestModel; | ||
}; | ||
}, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.