當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。