当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript typeorm.getRepository函数代码示例

本文整理汇总了TypeScript中typeorm.getRepository函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getRepository函数的具体用法?TypeScript getRepository怎么用?TypeScript getRepository使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了getRepository函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: authToken

router.post("/edit_user", async ctx => {
  await authToken(ctx, true);
  const {
    uid,
    email,
    note,
    enabled,
    isAdmin,
    isEmailVerified,
    regenerate,
  } = ctx.request.body;
  if (!uid) {
    return raiseApiError(400, "请求格式错误");
  }
  const user = await getRepository(User).findOneById(uid);
  if (!user) {
    return raiseApiError(404, "用户不存在");
  }
  user.email = email || user.email;
  user.note = note || user.note;
  user.enabled = enabled;
  user.isAdmin = isAdmin;
  user.isEmailVerified = isEmailVerified;
  if (regenerate) {
    user.setConnPassword();
    await user.allocConnPort();
    user.vmessUid = uuid();
  }
  await getRepository(User).save(user);
  await writeServerConfig();
  ctx.body = { message: "操作成功" };
});
开发者ID:coderfox,项目名称:Another-SS-Panel,代码行数:32,代码来源:api.ts

示例2: async

export const createTestData = async () => {
    await resetDatabase();

    /**
     * Create the following structure:
     *
     * ROOT
     *  |- C:       [dummy-image-1.jpg]
     *  |--- F1     [dummy-image-2.PNG, dummy-image-3.gif]
     *  |--- F2     [dummy-image-4.jpeg, dummy-image-5.TIFF]
     *  |------ F3  [dummy-image-6.jpg, dummy-image-7.png]
     *  |- D:
     *  |--- F4
     *  |------ F5
     *  |--------- F6
     */
    const folderRepo = getRepository(Folder);
    const c = await folderRepo.save(folderRepo.create({ name: 'C:' }));
    const f1 = await folderRepo.save(folderRepo.create({ name: 'F1', parent: c }));
    const f2 = await folderRepo.save(folderRepo.create({ name: 'F2', parent: c }));
    const f3 = await folderRepo.save(folderRepo.create({ name: 'F3', parent: f2 }));
    const d = await folderRepo.save(folderRepo.create({ name: 'D:' }));
    const f4 = await folderRepo.save(folderRepo.create({ name: 'F4', parent: d }));
    const f5 = await folderRepo.save(folderRepo.create({ name: 'F5', parent: f4 }));
    const f6 = await folderRepo.save(folderRepo.create({ name: 'F6', parent: f5 }));

    const imageRepo = getRepository(Image);
    const i1 = await imageRepo.save(imageRepo.create({ name: 'dummy-image-1', originalName: 'orig-image-1', extension: 'jpg', parentFolder: c }));
    const i2 = await imageRepo.save(imageRepo.create({ name: 'dummy-image-2', originalName: 'orig-image-2', extension: 'PNG', parentFolder: f1 }));
    const i3 = await imageRepo.save(imageRepo.create({ name: 'dummy-image-3', originalName: 'orig-image-3', extension: 'gif', parentFolder: f1 }));
    const i4 = await imageRepo.save(imageRepo.create({ name: 'dummy-image-4', originalName: 'orig-image-4', extension: 'jpeg', parentFolder: f2 }));
    const i5 = await imageRepo.save(imageRepo.create({ name: 'dummy-image-5', originalName: 'orig-image-5', extension: 'TIFF', parentFolder: f2 }));
    const i6 = await imageRepo.save(imageRepo.create({ name: 'dummy-image-6', originalName: 'orig-image-6', extension: 'jpg', parentFolder: f3 }));
    const i7 = await imageRepo.save(imageRepo.create({ name: 'dummy-image-7', originalName: 'orig-image-7', extension: 'png', parentFolder: f3 }));
};
开发者ID:pschild,项目名称:image-management-tool,代码行数:35,代码来源:test-utils.ts

示例3: endLogging

/**
 * When the user stops playing a game, call this function.
 * @param user
 */
async function endLogging(user: GuildMember, game: string) {
    const seconds: number = stats.timePlayed(user, game);
    stats.removeGame(user, game);

    if (seconds === null || seconds === 0) {
        console.error("Invalid seconds, skipping this log.");
        return;
    }

    const gameTimeRepository = getRepository(GameTime);
    const userRepository = getRepository(DiscordDBUser);
    const match = await userRepository.findOneById(user.id);

    if (!match) {
        console.error(`No user with id ${user.id} and username ${user.displayName} was found when adding gametime.`);
        return;
    }

    let newEntry = await gameTimeRepository.create();
    newEntry.secondsPlayed = seconds;
    newEntry.sessionEndDate = new Date(Date.now());
    newEntry.discordUser = match;
    newEntry.gameName = game;

    gameTimeRepository.save(newEntry);

    // If a valid number of seconds, be sure to add it to the database.
    // writeNewTimeRow(user, seconds);
}
开发者ID:Goyatuzo,项目名称:LurkerBot,代码行数:33,代码来源:game_tracker.ts

示例4: function

export default async function (bot: Client) {
    const serverRepository = getRepository(DiscordDBServer);
    const userRepository = getRepository(DiscordDBUser);

    const storedServers = await serverRepository.find({ relations: ['users'] });
    const storedUsers = await userRepository.find();

    let localServers: DiscordDBServer[] = [];
    let localUsers: DiscordDBUser[] = [];

    // We want the name of the servers, but while we're at it, populate the table.
    const guildNames = bot.guilds.array().map(guild => {
        let serverMatch = storedServers.find(dbServer => guild.id === dbServer.id);

        if (!serverMatch) {
            serverMatch = serverRepository.create({
                id: guild.id
            });
        }

        serverMatch.name = guild.name;

        localServers.push(serverMatch);

        const users = guild.members.array().map(guildMember => {
            const queryId = guildMember.user.id;

            let userMatch = storedUsers.find(dbUser => dbUser.id === queryId) || localUsers.find(userArr => userArr.id === queryId);

            if (!userMatch) {
                userMatch = userRepository.create({
                    id: queryId
                });
            }

            userMatch.username = guildMember.user.username;
            userMatch.discriminator = guildMember.user.discriminator

            if (!userMatch.servers) {
                userMatch.servers = [serverMatch];
            }
            else if (!serverMatch.users.some(dbUser => dbUser.id === userMatch.id)) {
                userMatch.servers.push(serverMatch);
            }

            return userMatch;
        });


        console.log(`Saved ${guild.name}`);

        return guild.name;
    });

    await serverRepository.save(localServers);
    await userRepository.save(localUsers);

    console.log(`Connected to all servers.`);
}
开发者ID:Goyatuzo,项目名称:LurkerBot,代码行数:59,代码来源:ready.ts

示例5: auth

router.post("/reset_password", async ctx => {
  const user = await auth(ctx);
  const { newPassword } = ctx.request.body;
  await user.setPassword(newPassword);
  await getRepository(User).save(user);
  ctx.body = { message: "修改成功" };
});
开发者ID:coderfox,项目名称:Another-SS-Panel,代码行数:7,代码来源:api.ts

示例6: raiseApiError

router.post("/reg", async ctx => {
  const { email, password, refcode } = ctx.request.body;
  if (!email || !password) {
    raiseApiError(400, "请求格式错误");
  }
  if (!(config.openRegister || refcode)) {
    if (email !== config.adminEmail) {
      raiseApiError(400, "未开放注册,请填写邀请码");
    }
  }
  const user = new User(email);
  await user.setPassword(password);
  user.setConnPassword();
  await user.allocConnPort();
  if (!config.openRegister && email !== config.adminEmail) {
    try {
      const refData = await decode<any>(refcode);
      if (refData.email !== email) {
        raiseApiError(403, "邀请码不适用于当前邮件地址");
      }
      user.note = refData.note;
    } catch (err) {
      if (err.status === 403) {
        throw err;
      } else {
        raiseApiError(403, "邀请码已过期");
      }
    }
  }
  await getRepository(User).save(user);
  await writeServerConfig();
  await validateEmail(user);
  ctx.status = 200;
  ctx.body = { message: "注册成功" };
});
开发者ID:coderfox,项目名称:Another-SS-Panel,代码行数:35,代码来源:api.ts

示例7: async

const auth = async (ctx: Context, requireAdmin = false): Promise<User> => {
  const { email, password } = ctx.request.body;
  if (!email || !password) {
    raiseApiError(400, "邮箱或密码未提供");
  }
  try {
    const user = await getRepository(User).findOne({ email });
    if (!user) {
      return raiseApiError(404, "用户不存在");
    }
    if (!(await user.checkPassword(password))) {
      return raiseApiError(403, "密码错误");
    }
    if (requireAdmin && !user.isAdmin) {
      return raiseApiError(403, "权限不足");
    }
    return user;
  } catch (err) {
    if (err.status) {
      throw err;
    } else {
      return raiseApiError(500, "服务器内部错误" + err.message);
    }
  }
};
开发者ID:coderfox,项目名称:Another-SS-Panel,代码行数:25,代码来源:api.ts

示例8: getUsers

    public getUsers(): Promise<UserModel[]> {
        const userRepository = getRepository(UserEntity);


        // return userRepository
        //     .createQueryBuilder('user')
        //     .where('user.id IN (:idList)', {idList: [1,2,3]})
        //     .getMany()
        //     .then(users => {
        //         const result = [];
        //         for (const u of users) {
        //             result.push(UserModel.fromEntity(u));
        //         }
        //         return result;
        //     });

        return userRepository
            .find()
            .then(users => {
                const result = [];
                for (const u of users) {
                    result.push(UserModel.fromEntity(u));
                }
                return result;
            });
    }
开发者ID:mowgliLab,项目名称:baguette-garnie,代码行数:26,代码来源:user.bl.ts

示例9: getUserDefaultTodos

export async function getUserDefaultTodos({ userId, limit, offset }): Promise<Todo[]> {
  return await getRepository(Todo)
    .createQueryBuilder('todo')
    .where('todo.creatorId = :creatorId AND isDelete = false', { creatorId: userId })
    .orderBy('todo.updatedAt', 'DESC')
    .limit(limit)
    .offset(offset)
    .getMany();
}
开发者ID:A-Horse,项目名称:bblist-backend,代码行数:9,代码来源:getTodos.ts

示例10: updateOrder

 public updateOrder(orderId: number, orderStatus: string): Promise<boolean> {
     const orderRepository = getRepository(OrderEntity);
     return orderRepository
         .updateById(orderId, {status: orderStatus})
         .then(res => {
             console.log(res);
             return true;
         });
 }
开发者ID:mowgliLab,项目名称:baguette-garnie,代码行数:9,代码来源:order.bl.ts

示例11: getCustomSandwichesOfUser

 public getCustomSandwichesOfUser(userId: number): Promise<Array<SandwichModel>> {
     const sandwichRepository = getRepository(SandwichEntity);
     return sandwichRepository.createQueryBuilder('sandwich')
         .leftJoinAndSelect('sandwich.toppings', 'topping')
         .leftJoinAndSelect('sandwich.bread', 'bread')
         .leftJoin('sandwich.user', 'user')
         .where(`user.id = ${userId}`)
         .getMany().then(sandwiches => _.map(sandwiches, s => SandwichModel.fromEntity(s)));
 }
开发者ID:mowgliLab,项目名称:baguette-garnie,代码行数:9,代码来源:user.bl.ts

示例12: getSandwich

 public getSandwich(sandwichId: number): Promise<SandwichModel> {
     const sandwichRepository = getRepository(SandwichEntity);
     return sandwichRepository.createQueryBuilder('sandwich')
         .leftJoinAndSelect('sandwich.toppings', 'topping')
         .leftJoinAndSelect('sandwich.bread', 'bread')
         .where(`sandwich.id = ${sandwichId}`).getOne()
         .then(sandwich => {
             return SandwichModel.fromEntity(sandwich);
         });
 }
开发者ID:mowgliLab,项目名称:baguette-garnie,代码行数:10,代码来源:sandwich.bl.ts

示例13: saveCustomSandwich

    public saveCustomSandwich(sandwich: SandwichModel, user: UserModel): Promise<any> {
        const sandwichRepository = getRepository(SandwichEntity);
        const sandwichEntity = SandwichModel.toEntity(sandwich, true);
        sandwichEntity.user = UserModel.toEntity(user);
        return sandwichRepository
            .save(sandwichEntity)
            .then(res => res)
            .catch(err => false);

    }
开发者ID:mowgliLab,项目名称:baguette-garnie,代码行数:10,代码来源:sandwich.bl.ts

示例14: UserEntity

  users.forEach(async (user: UserModel) => {
    const newUser = new UserEntity();

    newUser.id = user.get('id');
    newUser.hash = user.get('password');
    newUser.email = user.get('email');
    newUser.username = user.get('username');

    await getRepository(UserEntity).save(newUser);
  });
开发者ID:A-Horse,项目名称:bblist-backend,代码行数:10,代码来源:migrations.ts

示例15: getActiveMenu

 public getActiveMenu (): Promise<MenuModel> {
     const menuRepository = getRepository(MenuEntity);
     return menuRepository.createQueryBuilder('menu')
         .leftJoinAndSelect('menu.sandwichOnMenus', 'sandwichOnMenu')
         .leftJoinAndSelect('sandwichOnMenu.sandwich', 'sandwich')
         .leftJoinAndSelect('sandwich.toppings', 'topping')
         .leftJoinAndSelect('sandwich.bread', 'bread')
         .where('menu.isActive = true').orderBy('sandwichOnMenu.orderNumber, sandwich.name').getOne().then(menu => {
             return MenuModel.fromEntity(menu);
     });
 }
开发者ID:mowgliLab,项目名称:baguette-garnie,代码行数:11,代码来源:menu.bl.ts


注:本文中的typeorm.getRepository函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。