本文整理汇总了TypeScript中typeorm.getManager函数的典型用法代码示例。如果您正苦于以下问题:TypeScript getManager函数的具体用法?TypeScript getManager怎么用?TypeScript getManager使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getManager函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: addPlayerToTeam
public async addPlayerToTeam(player: Player, team: Team): Promise<Player> {
player.teams = [team];
await getManager().getRepository(Player).save(player);
const sharePromises: Array<Promise<Share>> = [];
for (const share of player.shares) {
share.player = player;
player.shares.push(share);
sharePromises.push(getManager().getRepository(Share).save(share));
}
await Promise.all(sharePromises);
return player;
}
示例2: getAllSeasonsForMenu
public async getAllSeasonsForMenu(): Promise<SeasonMenuItem[]> {
const season = await getManager().getRepository(Season).createQueryBuilder("season")
.orderBy("season.id", "DESC")
.getMany();
return season.map((s) => new SeasonMenuItem(s.name, s.slug));
}
示例3: updateRatingForMovie
public async updateRatingForMovie(movie: Movie, rating: number): Promise<void> {
await getManager().getRepository(Movie).createQueryBuilder("movies")
.update()
.set({ rating })
.where({ id: movie.id })
.execute();
}
示例4: createUser
public static async createUser (ctx: BaseContext) {
// get a user repository to perform operations with user
const userRepository: Repository<User> = getManager().getRepository(User);
// build up entity user to be saved
const userToBeSaved: User = new User();
userToBeSaved.name = ctx.request.body.name;
userToBeSaved.email = ctx.request.body.email;
// validate user entity
const errors: ValidationError[] = await validate(userToBeSaved); // errors is an array of validation errors
if (errors.length > 0) {
// return bad request status code and errors array
ctx.status = 400;
ctx.body = errors;
} else {
// save the user contained in the POST body
const user = await userRepository.save(userToBeSaved);
// return created status code and updated user
ctx.status = 201;
ctx.body = user;
}
}
示例5: getMovie
public async getMovie(id: number, team: Team): Promise<Movie | undefined> {
return await getManager().getRepository(Movie).createQueryBuilder("movie")
.leftJoinAndSelect("movie.earnings", "earnings")
.leftJoinAndSelect("movie.shares", "shares")
.where("movie.id = :id", { id })
.andWhere("shares.playerId IN (:...players)", { players: team.players.map((p) => p.id) })
.getOne();
}
示例6: getTeam
public async getTeam(id: number): Promise<Team> {
const team = await getManager().getRepository(Team).createQueryBuilder("team")
.innerJoinAndSelect("team.players", "players")
.innerJoinAndSelect("team.season", "season")
.where("team.id = :id", { id })
.getOne();
return team!;
}
示例7: postGetAllAction
export async function postGetAllAction(context: Context) {
// get a post repository to perform operations with post
const postRepository = getManager().getRepository(Post);
// load all posts
const posts = await postRepository.find();
// return loaded posts
context.body = posts;
}
示例8: getUsers
public static async getUsers (ctx: BaseContext) {
// get a user repository to perform operations with user
const userRepository: Repository<User> = getManager().getRepository(User);
// load all users
const users: User[] = await userRepository.find();
// return loaded users
ctx.body = users;
}
示例9: getSelectedSeason
public async getSelectedSeason(seasonSlug: string | undefined): Promise<Season | undefined> {
let slug: string;
if (seasonSlug === undefined) {
const maxSeason = await getManager().getRepository(Season).createQueryBuilder("season")
.orderBy("id", "DESC")
.getOne();
slug = maxSeason!.slug;
} else {
slug = seasonSlug;
}
const season = await getManager().getRepository(Season).createQueryBuilder("season")
.leftJoinAndSelect("season.teams", "teams")
.leftJoinAndSelect("season.movies", "movies")
.leftJoinAndSelect("season.urls", "urls")
.leftJoinAndSelect("movies.earnings", "earnings")
.leftJoinAndSelect("movies.shares", "shares")
.where("season.slug LIKE :slug", { slug })
.getOne();
return season;
}
示例10: postSaveAction
export async function postSaveAction(context: Context) {
// get a post repository to perform operations with post
const postRepository = getManager().getRepository(Post);
// create a real post object from post json object sent over http
const newPost = postRepository.create(context.request.body);
// save received post
await postRepository.save(newPost);
// return saved post back
context.body = newPost;
}