Skip to content

Instantly share code, notes, and snippets.

View felinto-dev's full-sized avatar
Refactor all the things

Émerson Felinto felinto-dev

Refactor all the things
View GitHub Profile
@felinto-dev
felinto-dev / api-nests.service.ts
Created August 21, 2022 10:20
Axios Cache Wrapper for NestJS
import { HttpService } from '@nestjs/axios';
import { Injectable } from '@nestjs/common';
import {
setupCache,
buildMemoryStorage,
defaultKeyGenerator,
} from 'axios-cache-interceptor';
@Injectable()
export class ApiService {
// Get products that does not have item
db.getCollection('gplzone').find({ 'item': { $exists: false } })
// Get products that has notes associated
db.getCollection('gplzone').find({ 'note': { $exists: true } })
// Get products that was not possible to scrape zip content
db.getCollection('gplzone').find({
'item.product_version.is_double_zipped': true
})
@felinto-dev
felinto-dev / get-command-args.ts
Created April 15, 2021 07:53
Get commands args from context in Telegram
import { deunionize } from 'telegraf';
import { Context } from '../interfaces';
export const getCommandArgs = (ctx: Context): string => {
const messageText = deunionize(ctx.message).text;
const argsFromCommandRegex = /\/(?:\w+)(?:@\w+?_bot)? (?<args>.*)/i;
const args = argsFromCommandRegex.exec(messageText);
@felinto-dev
felinto-dev / storage.module.ts
Last active August 8, 2022 14:19
After a lot of headaches with plugins that propose to be a wrapper between nestjs and aws-sdk, I decided to configure the dependency injection by myself and the result was not bad. You can use this code as the basis for any cloud storage S3-compatible. I am using @nestjs/config to manage the settings of environment variables. For additional inst…
import { S3 } from 'aws-sdk';
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { scalewayConfig } from '@/app/config/scaleway.config';
import { StorageService } from './services/storage.service';
@Module({
imports: [ConfigModule.forFeature(scalewayConfig)],
providers: [