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
require('dotenv').config() | |
const { DataMapper, DbHelper } = require('api-data-tools'); | |
console.log('dropDb', process.env.DATABASE_URL); | |
async function main() { | |
DbHelper.initialize(); | |
let r = []; |
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
/* Usage: | |
// init: | |
this.db = new IDB(); | |
this.db.open(DBNAME); | |
this.db.addStore(DBNAME, { autoIncrement: true }, [ | |
{ name: 'id', key: 'id', params: { unique: true } }, | |
{ name: 'word, language', key: [ 'word', 'language' ], params: { unique: true } }, | |
]); |
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
import LocalStorage from 'lib/utils/LocalStorage'; | |
export default class Store { | |
id: string; | |
items: any; | |
autoSave = true; | |
constructor(storeId, items = {}, autoSave = true) { | |
this.id = storeId; |
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
// Client: | |
onImagesAdded = (e) => { | |
try { | |
console.log('added', e) | |
Array.from(e.target.files).forEach(async (f: any) => { | |
let sUrl = await S3Service.getSignedUrl(f.name, f.type); | |
console.log('got signed url', sUrl) | |
let r = await this.sendFile(f, sUrl); | |
}) |
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
export default class Response { | |
static success(res, data) { | |
const r = { | |
success: true | |
} | |
if (data) { | |
r.data = data | |
} |
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
const { getRedisClient } = require('./redis/redis') | |
redis = getRedisClient() | |
const EXPIRE_DEFAULT = 60*60; // seconds = 1hr | |
// App-wide cache. Just a wrapper for redis. | |
class Cache { | |
async get(id) { |
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
export class DateUtils { | |
public static dateToIsoString(date: Date | string): string | null { | |
return date.toISOString(); | |
} | |
public static getDateFromMysql(isoDateStr: string): Date { | |
var dateParts = isoDateStr.split("-"); | |
return new Date(dateParts[0], dateParts[1] - 1, dateParts[2].substr(0, 2)); | |
} |
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
"setup": "npm install && rm -rf scripts/migrations && rm config/.curr.schema.json && npm run migrate", | |
"dev": "concurrently --kill-others \"npm run build-watcher\" \"npm run build-reload\"", | |
"build-watcher": "nodemon --watch './src/**/*' -e ts,tsx,js,jsx,scss,html,json,env --exec \"npm run build\"", | |
"build-reload": "nodemon --signal SIGTERM build/index.js", |
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
// trigger upload dialog: | |
this.importFile.current.click(); | |
onFileImportChange = (e) => { | |
try { | |
const reader = new FileReader(); | |
reader.addEventListener('load', () => { | |
let data = JSON.parse(reader.result); | |
this.setState(data); | |
}); |
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
/* | |
Usage example: | |
import Validation from 'Validation.ts'; | |
let data = { | |
username: "aUsername", | |
password: "aPassword", | |
confirmPassword: "aPassword" | |
} |