Skip to content

Instantly share code, notes, and snippets.

View docentedev's full-sized avatar
🇨🇱
Pensando!

Claudio docentedev

🇨🇱
Pensando!
View GitHub Profile
@docentedev
docentedev / index.utils.ts
Created December 15, 2022 19:34
index.utils.ts
export const textNormalize = (str: string) => {
const value = str.normalize('NFD').replace(/[\u0300-\u036f]/g, '');
if (value === undefined) return '';
return value
.trim()
.replace(/[^a-z0-9_]+/gi, '-')
.replace(/^-|-$/g, '')
.toLowerCase();
};
@docentedev
docentedev / dd.style.ts
Created December 15, 2022 19:29
dd.style.ts
import styled from 'styled-components';
export const Container = styled.div`
position: relative;
input {
padding: 8px 50px 8px 16px;
width: 100%;
border: none;
border-radius: 8px;
height: 46px;
@docentedev
docentedev / dd.tsx
Created December 15, 2022 19:29
dd.tsx
/* eslint-disable @typescript-eslint/no-explicit-any */
import React, { useRef, useState } from 'react';
import useClickOutside from '../../hooks/useClickOutside';
import Hint from '../hint';
import Icon from '../icon/v1';
import { Container } from './index.style';
import { textNormalize } from './index.utils';
type Option = {
value: string;
export const clearSessionStorage = () => {
for (const key in sessionStorage) {
if (key.includes('updateIfNewData__')) sessionStorage.removeItem(key);
}
};
clearSessionStorage();
const updateIfNewData = (
{ debug = false }: { debug: boolean } = { debug: false },
) => {
const tryUpdate = <T>(
/* eslint-disable @typescript-eslint/no-explicit-any */
import { AxiosRequestConfig, AxiosResponseHeaders } from 'axios';
import { useEffect, useState } from 'react';
import updateIfNewData from '../../utils/updateIfNewData';
export type InitialState<T> = {
isLoading: boolean;
data: T | null;
error: any;
isError: boolean | null;
import { Controller, Get, Param } from '@nestjs/common';
import { AppService } from './app.service';
function LogErrorDecorator(bubble = true) {
console.log('Start');
return (
target: any,
propertyKey: string,
propertyDescriptor: PropertyDescriptor,
) => {

URL localhost:3001/api/v1/musicians?size=1&page=2

const query = {
  text: 'SELECT m.id, m.first_name, m.last_name, m.second_last_name, m.second_name, m.birth_date, m.death_date, m.city_fk, m.alias, c.name as city_name, co.nicename as country_name, m.image FROM musician AS m INNER JOIN city AS c ON c.id = m.city_fk INNER JOIN country AS co ON co.iso = c.country_iso_fk ORDER BY m.id desc LIMIT $2  OFFSET (($1 - 1) * $2)',
  values: [ '2', '1' ]
}
const express = require('express')
const app = express()
// localhost:3000/api/v1/cursos
app.get('/api/v1/cursos', (req, res) => {
res.send('Cursos')
})
app.get('/api/v2/cursos', (req, res) => {
res.send(['Curso 1', 'Curso 2'])
interface QueryBuilderProps {
table: string;
as?: string[];
select?: string;
fields: string[];
run?: (sql: string, values: any[], single: Boolean) => Promise<any>;
debug?: boolean;
mutationFields?: string[];
}
const print = (value) => console.log(value)
class QueryBuilder {
#sqlText = ''
#sqlTable = null
#sqlSelect = '*'
#sqlAlias = {}
#sqlFields = []
#sqlSelectAlias = {}
#sqlValues = []
constructor ({ table, as = [], select = '*', fields = [] }) {