Skip to content

Instantly share code, notes, and snippets.

View Romakita's full-sized avatar
🎯
Focusing

Romain Lenzotti Romakita

🎯
Focusing
View GitHub Profile
@Romakita
Romakita / squaregameservice.ts
Created December 18, 2017 06:52
Example of Socket.io integration with Ts.ED
import {Args, Broadcast, Input, Nsp, Socket, SocketService, SocketSession} from "ts-express-decorators/socketio";
import {$log} from "ts-log-debug";
import {PlayerSG} from "../models/PlayerSG";
@SocketService("/square-game")
export class SquareGameService {
private AUTO_INCREMENT = 0;
/**
@Romakita
Romakita / tools.ts
Created May 14, 2018 06:28
Utils for unit test in Typescript with mocha + chai + sinon
import * as Chai from "chai";
import * as ChaiAsPromised from "chai-as-promised";
import * as SinonLib from "sinon";
import {SinonStub} from "sinon";
import * as SinonChai from "sinon-chai";
import {$log} from "ts-log-debug"; // your logger
Chai.should();
Chai.use(SinonChai);
Chai.use(ChaiAsPromised);
@Romakita
Romakita / CarsClient.js
Created July 9, 2019 08:45
CarsClient example
const HOST = ''
export async function getCars() {
// should be axios
// const { data } = await axios.get(`${HOST}/cars`)
// return data
//
// Right now we don't have server so we create mocked data
return [
@Romakita
Romakita / FormBuilder.jsx
Last active November 4, 2019 06:59
React formio formbuilder.jsx
import React from 'react'
import PropTypes from 'prop-types'
import cloneDeep from 'lodash/cloneDeep'
import AllComponents from 'formiojs/components'
import Components from 'formiojs/components/Components'
import FormioFormBuilder from 'formiojs/FormBuilder'
Components.setComponents(AllComponents)
const EVENTS = [
@Romakita
Romakita / AtlassianHttpClient.ts
Last active January 31, 2020 10:38
Wrap httpClient from atlassian-connect-express into a Ts.ED service
import {Service} from "@tsed/common"
// add all imports
export interface AtlassianRequestOptions {
headers: {
[key: string]: string;
},
[key: string]: any
}
@Romakita
Romakita / CrudController.ts
Last active April 4, 2020 09:37
Crud Mongoose Controller
import {Type, nameOf} from "@tsed/core";
const {paramCase} = require("change-case");
export interface ICrudControllerOptions {
path?: string;
model: Type<any>
}
export function CrudController(options: ICrudControllerOptions) {
return (target: Type<any>) =>{
@Romakita
Romakita / BotComponentsRegistry.ts
Last active November 17, 2020 15:36
Oracle Bot with Ts.ED
import {GlobalProviders, Provider, TypedProvidersRegistry} from "@tsed/di";
export const PROVIDER_TYPE_BOT_COMPONENTS = "botComponents";
export const botComponentsRegistry: TypedProvidersRegistry = GlobalProviders.createRegistry(PROVIDER_TYPE_BOT_COMPONENTS, Provider, {
injectable: true
});
export const registerBotComponent = GlobalProviders.createRegisterFn(PROVIDER_TYPE_BOT_COMPONENTS);
@Romakita
Romakita / Pageable.ts
Last active December 4, 2020 07:51
Pagination example with Ts.ED
import {
CollectionOf,
Default,
Description,
Integer,
MaxItems,
Min,
MinLength,
Property,
Required,
import { Injectable, OnInit, OnDestroy } from "@tsed/common";
import { PrismaClient } from "@prisma/client";
@Injectable()
export class PrismaService extends PrismaClient implements OnInit, OnDestroy {
async $onInit() {
await this.$connect();
}
async $onDestroy() {
@Romakita
Romakita / UsersController.ts
Created May 24, 2021 15:40
Prisma UsersController
import {BodyParams, Controller, Get, PathParams, Post} from "@tsed/common";
import {Inject} from "@tsed/di";
import {PrismaService} from "../services/PrismaService";
import {Groups, Required, Email, Returns, Summary} from "@tsed/schema";
import {User} from "@prisma/client";
class UserModel implements User {
@Required()
@Groups("!creation")
id: number;