How to use typeorm-typedi-extensions - 10 common examples

To help you get started, we’ve selected a few typeorm-typedi-extensions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github rotemgrim / rooster-x / src / main / repositories / UserRepository.ts View on Github external
import {Container, Service} from "typedi";
import {Connection} from "typeorm";
import {InjectConnection} from "typeorm-typedi-extensions";
import {User} from "../../entity/User";
import {UserEpisode} from "../../entity/UserEpisode";
import {UserMetaData} from "../../entity/UserMetaData";
import * as path from "path";
import * as fs from "fs";
import AppGlobal from "../helpers/AppGlobal";

@Service()
export class UserRepository {

    @InjectConnection("reading")
    private connection: Connection;

    public getAllUsers() {
        const userRepo = this.connection.manager.getRepository(User);
        return userRepo.find();
    }

    public getUser(id) {
        console.log("find user by id", id);
        const userRepo = this.connection.manager.getRepository(User);
        return userRepo.findOne(id);
    }

    public createUser(payload: User) {
        console.log(payload);
        const userRepo = this.connection.manager.getRepository(User);
github rotemgrim / rooster-x / src / main / repositories / TorrentsRepository.ts View on Github external
import {MetaData} from "../../entity/MetaData";
import RoRest from "../services/RoRest";
import {HTMLElement, parse} from "node-html-parser";
import {TorrentFile} from "../../entity/TorrentFile";
import {IMediaEntry} from "../../common/models/IMediaEntry";
import * as ptn from "../../common/lib/parse-torrent-name";
import {MediaRepository} from "./MediaRepository";
import IMDBController from "../controllers/IMDBController";
import {Alias} from "../../entity/Alias";

type TorrentLinks = Array<{title: string, magnet: string, timestamp: number}>;

@Service()
export class TorrentsRepository {

    @InjectConnection("reading")
    private connection: Connection;

    public static startTorrentsWatch(): void {
        setInterval(() => {
            const d = new Date();
            const minutes = d.getMinutes();
            const hours = d.getHours();
            if (hours === 18 && minutes >= 15 && minutes < 45) {
                Container.get(TorrentsRepository).reprocessTorrents()
                    .catch(console.error);
            }
        }, 1800 * 1000);
    }

    public async getAllTorrents() {
        const metaRepo = this.connection.manager.getRepository(MetaData);
github rotemgrim / rooster-x / src / main / repositories / GenreRepository.ts View on Github external
import {Container, Service} from "typedi";
import {Connection} from "typeorm";
import {InjectConnection} from "typeorm-typedi-extensions";
import {Genre} from "../../entity/Genre";
import {MetaData} from "../../entity/MetaData";
import MediaController from "../controllers/MediaController";

@Service()
export class GenreRepository {

    @InjectConnection("reading")
    private connection: Connection;

    public getAllGenres() {
        const userRepo = this.connection.manager.getRepository(Genre);
        return userRepo.find();
    }

    public async reprocessAllGenres() {
        const metaRepo = this.connection.manager.getRepository(MetaData);
        const allMeta = await metaRepo.find();
        let allGenres: string[] = [];
        if (allMeta) {
            for (const meta of allMeta) {
                if (meta && meta.genres) {
                    const genres = meta.genres.split(", ") as string[];
                    if (genres) {
github niklaskorz / nkchat / server / src / resolvers / MessageResolver.ts View on Github external
constructor(
    @InjectRepository(Message)
    private messageRepository: MongoRepository,
    @InjectRepository(Room) private roomRepository: MongoRepository,
    @InjectRepository(User) private userRepository: MongoRepository,
  ) {}
github birkir / prime / packages / prime-core / src / modules / internal / resolvers / UserResolver.ts View on Github external
import { processWebhooks } from '../../../utils/processWebhooks';
import { UserMetaRepository } from '../repositories/UserMetaRepository';
import { UserRepository } from '../repositories/UserRepository';
import { ConnectionArgs, createConnectionType } from '../types/createConnectionType';
import { UpdateUserInput } from '../types/UpdateUserInput';
import { Authorized } from '../utils/Authorized';
import { ExtendedConnection } from '../utils/ExtendedConnection';

const UserConnection = createConnectionType(User);

@Resolver(of => User)
export class UserResolver {
  @InjectRepository(UserRepository)
  private readonly userRepository: UserRepository;

  @InjectRepository(UserMetaRepository)
  private readonly userMetaRepository: UserMetaRepository;

  @InjectRepository(UserEmail)
  private readonly userEmailRepository: Repository;

  @Authorized()
  @Query(returns => User)
  public User(
    @Arg('id', type => ID) id: string //
  ) {
    return this.userRepository.findOneOrFail(id);
  }

  @Authorized()
  @Query(returns => User)
  public async getUser(@Ctx() context: Context) {
github goldcaddy77 / warthog / examples / 04-many-to-many-relationship / src / simple-join-table / post.resolver.ts View on Github external
  constructor(@InjectRepository(Post) public readonly postRepository: Repository) {
    super(Post, postRepository);
  }
github goldcaddy77 / warthog / examples / 01-simple-model / src / user.resolver.ts View on Github external
  constructor(@InjectRepository(User) public readonly userRepository: Repository) {
    super(User, userRepository);
  }
github benawad / codeponder / packages / server / src / modules / notifications / resolver.ts View on Github external
Resolver,
  UseMiddleware,
} from "type-graphql";
import { FindOneOptions, LessThan, Repository } from "typeorm";
import { InjectRepository } from "typeorm-typedi-extensions";
import { Comment } from "../../entity/Comment";
import { QuestionCommentNotification } from "../../entity/QuestionCommentNotification";
import { MyContext } from "../../types/Context";
import { isAuthenticated } from "../shared/middleware/isAuthenticated";
import { OkResponse } from "../shared/OkResponse";
import { NotificationsResponse } from "./response";

const NOTIF_LIMIT = 50;
@Resolver(Comment)
export class CommentResolver {
  @InjectRepository(QuestionCommentNotification)
  private readonly questionCommentNotificationRepo: Repository<
    QuestionCommentNotification
  >;

  @Query(() => NotificationsResponse)
  @UseMiddleware(isAuthenticated)
  async notifications(
    @Ctx() { req }: MyContext,
    @Arg("cursor", { nullable: true }) cursor?: string
  ): Promise {
    const where: FindOneOptions["where"] = {
      userToNotifyId: req.session && req.session.userId,
    };

    if (cursor) {
      where.createdAt = LessThan(cursor);
github goldcaddy77 / warthog / examples / 07-feature-flags / src / feature-flag-segment / feature-flag-segment.service.ts View on Github external
constructor(
    @InjectRepository(FeatureFlagSegment)
    protected readonly repository: Repository,
    @Inject('EnvironmentService') readonly environmentService: EnvironmentService,
    @Inject('FeatureFlagService') readonly featureFlagService: FeatureFlagService,
    @Inject('ProjectService') readonly projectService: ProjectService,
    @Inject('SegmentService') readonly segmentService: SegmentService
  ) {
    super(FeatureFlagSegment, repository);
  }
github goldcaddy77 / warthog / examples / 04-many-to-many-relationship / src / simple-join-table / author.resolver.ts View on Github external
  constructor(@InjectRepository(Author) public readonly authorRepository: Repository) {
    super(Author, authorRepository);
  }

typeorm-typedi-extensions

Dependency injection and service container integration with TypeORM using TypeDI library.

MIT
Latest version published 4 years ago

Package Health Score

54 / 100
Full package analysis

Similar packages