Chore: Migrate database/services and database/utils to TS (#3708)
* migrate database services and utils to ts * Migrate tests Co-authored-by: Diego Mello <diegolmello@gmail.com>
This commit is contained in:
parent
5e60f58bb3
commit
88172f0aa9
|
@ -1,9 +1,10 @@
|
||||||
import database from '..';
|
import database from '..';
|
||||||
|
import { TAppDatabase } from '../interfaces';
|
||||||
import { MESSAGES_TABLE } from '../model/Message';
|
import { MESSAGES_TABLE } from '../model/Message';
|
||||||
|
|
||||||
const getCollection = db => db.get(MESSAGES_TABLE);
|
const getCollection = (db: TAppDatabase) => db.get(MESSAGES_TABLE);
|
||||||
|
|
||||||
export const getMessageById = async messageId => {
|
export const getMessageById = async (messageId: string) => {
|
||||||
const db = database.active;
|
const db = database.active;
|
||||||
const messageCollection = getCollection(db);
|
const messageCollection = getCollection(db);
|
||||||
try {
|
try {
|
|
@ -1,9 +1,10 @@
|
||||||
import database from '..';
|
import database from '..';
|
||||||
|
import { TAppDatabase } from '../interfaces';
|
||||||
import { THREADS_TABLE } from '../model/Thread';
|
import { THREADS_TABLE } from '../model/Thread';
|
||||||
|
|
||||||
const getCollection = db => db.get(THREADS_TABLE);
|
const getCollection = (db: TAppDatabase) => db.get(THREADS_TABLE);
|
||||||
|
|
||||||
export const getThreadById = async tmid => {
|
export const getThreadById = async (tmid: string) => {
|
||||||
const db = database.active;
|
const db = database.active;
|
||||||
const threadCollection = getCollection(db);
|
const threadCollection = getCollection(db);
|
||||||
try {
|
try {
|
|
@ -1,9 +1,10 @@
|
||||||
import database from '..';
|
import database from '..';
|
||||||
|
import { TAppDatabase } from '../interfaces';
|
||||||
import { THREAD_MESSAGES_TABLE } from '../model/ThreadMessage';
|
import { THREAD_MESSAGES_TABLE } from '../model/ThreadMessage';
|
||||||
|
|
||||||
const getCollection = db => db.get(THREAD_MESSAGES_TABLE);
|
const getCollection = (db: TAppDatabase) => db.get(THREAD_MESSAGES_TABLE);
|
||||||
|
|
||||||
export const getThreadMessageById = async messageId => {
|
export const getThreadMessageById = async (messageId: string) => {
|
||||||
const db = database.active;
|
const db = database.active;
|
||||||
const threadMessageCollection = getCollection(db);
|
const threadMessageCollection = getCollection(db);
|
||||||
try {
|
try {
|
|
@ -1,7 +0,0 @@
|
||||||
import XRegExp from 'xregexp';
|
|
||||||
|
|
||||||
// Matches letters from any alphabet and numbers
|
|
||||||
const likeStringRegex = new XRegExp('[^\\p{L}\\p{Nd}]', 'g');
|
|
||||||
export const sanitizeLikeString = str => str?.replace(likeStringRegex, '_');
|
|
||||||
|
|
||||||
export const sanitizer = r => r;
|
|
|
@ -1,14 +1,12 @@
|
||||||
/* eslint-disable no-undef */
|
|
||||||
import * as utils from './utils';
|
import * as utils from './utils';
|
||||||
|
|
||||||
describe('sanitizeLikeStringTester', () => {
|
describe('sanitizeLikeStringTester', () => {
|
||||||
// example chars that shouldn't return
|
// example chars that shouldn't return
|
||||||
const disallowedChars = ',./;[]!@#$%^&*()_-=+~';
|
const disallowedChars = ',./;[]!@#$%^&*()_-=+~';
|
||||||
const sanitizeLikeStringTester = str =>
|
const sanitizeLikeStringTester = (str: string) =>
|
||||||
expect(utils.sanitizeLikeString(`${str}${disallowedChars}`)).toBe(`${str}${'_'.repeat(disallowedChars.length)}`);
|
expect(utils.sanitizeLikeString(`${str}${disallowedChars}`)).toBe(`${str}${'_'.repeat(disallowedChars.length)}`);
|
||||||
|
|
||||||
test('render empty', () => {
|
test('render empty', () => {
|
||||||
expect(utils.sanitizeLikeString(null)).toBe(undefined);
|
|
||||||
expect(utils.sanitizeLikeString('')).toBe('');
|
expect(utils.sanitizeLikeString('')).toBe('');
|
||||||
expect(utils.sanitizeLikeString(undefined)).toBe(undefined);
|
expect(utils.sanitizeLikeString(undefined)).toBe(undefined);
|
||||||
});
|
});
|
|
@ -0,0 +1,7 @@
|
||||||
|
import XRegExp from 'xregexp';
|
||||||
|
|
||||||
|
// Matches letters from any alphabet and numbers
|
||||||
|
const likeStringRegex = XRegExp('[^\\p{L}\\p{Nd}]', 'g');
|
||||||
|
export const sanitizeLikeString = (str?: string): string | undefined => str?.replace(likeStringRegex, '_');
|
||||||
|
|
||||||
|
export const sanitizer = (r: object): object => r;
|
Loading…
Reference in New Issue