-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: ramda,firebase and search-api
- Loading branch information
Showing
67 changed files
with
3,796 additions
and
5,039 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
config/* | ||
scripts/* | ||
public/* | ||
*.test.tsx" |
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,48 +1,59 @@ | ||
const fs = require("fs"); | ||
const { getFirebaseData } = require("./firebase"); | ||
const databaseName = { dev: "dev-database.json", prod: "prod-database.json" }; | ||
import fs from "node:fs"; | ||
import { getFirebaseData } from "./firebase"; | ||
import { isSameHour } from "date-fns"; | ||
|
||
const databaseName: { dev: string; prod: string } = { | ||
dev: "dev-database.json", | ||
prod: "prod-database.json" | ||
}; | ||
|
||
const databaseFolder = "./"; | ||
const { isSameHour } = require("date-fns"); | ||
|
||
const checkDatabaseFileWrittenSameHour = () => { | ||
interface DatabaseFile { | ||
timestamp: string; | ||
} | ||
|
||
const checkDatabaseFileWrittenSameHour = ( | ||
databaseID: "dev" | "prod" | ||
): boolean => { | ||
try { | ||
const { timestamp } = openDatabaseFile(databaseID); | ||
return isSameHour(new Date(timestamp), new Date()); | ||
} catch (e) { | ||
} catch { | ||
return false; | ||
} | ||
}; | ||
|
||
const openDatabaseFile = databaseID => { | ||
const openDatabaseFile = (databaseID: "dev" | "prod"): DatabaseFile => { | ||
const file = fs.readFileSync( | ||
`${databaseFolder}/${databaseName[databaseID]}`, | ||
"utf8" | ||
); | ||
return JSON.parse(file); | ||
}; | ||
|
||
const writeDatabaseFile = (object, path) => { | ||
const writeDatabaseFile = (object: unknown, path: string): void => { | ||
const fileJSON = JSON.stringify(object); | ||
fs.writeFileSync(path, fileJSON); | ||
}; | ||
|
||
const writeFirebaseDataToDatabaseFile = async databaseID => { | ||
const writeFirebaseDataToDatabaseFile = async ( | ||
databaseID: "dev" | "prod" | ||
): Promise<void> => { | ||
const fireBaseData = await getFirebaseData(databaseID); | ||
writeDatabaseFile( | ||
fireBaseData, | ||
`${databaseFolder}/${databaseName[databaseID]}` | ||
); | ||
}; | ||
|
||
const getDatabase = async databaseID => { | ||
export const getDatabase = async ( | ||
databaseID: "dev" | "prod" | ||
): Promise<DatabaseFile> => { | ||
const sameHour = checkDatabaseFileWrittenSameHour(databaseID); | ||
|
||
if (sameHour === false) { | ||
if (!sameHour) { | ||
await writeFirebaseDataToDatabaseFile(databaseID); | ||
} | ||
return openDatabaseFile(databaseID); | ||
}; | ||
|
||
module.exports = { | ||
getDatabase | ||
}; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.