async isExist(id: number): Promise<boolean> { const boilingPoint = await this.boilingPointRepository.findOne({ id, }, { select: ['id'], }); return boilingPoint !== null; }
async createCategory(createBookCategoryDto: CreateBookCategoryDto) { const category = new BookCategory(); category.name = createBookCategoryDto.name; category.sequence = createBookCategoryDto.sequence; category.pathname = createBookCategoryDto.pathname; category.createdAt = new Date(); category.updatedAt = category.createdAt; return await this.bookCategoryRepository.save(category); }
async updateChapterTitle(id: number, name: string, userID: number) { return await this.handBookChapterRepository.update({ id, userID, }, { name, }); }
async function run() { const connection = await createConnection(config.db); await addColumn(connection); // tslint:disable-next-line: no-console console.log('----------------- all done -----------------'); process.exit(0); }()
async findByPhoneOrUsername(phone: string, username: string): Promise<User | undefined> { const users: Array<User> = await this.userRepository.createQueryBuilder() .select(['id', 'phone', 'username']) .where('phone = :phone', { phone }) .orWhere('username = :username', { username }) .limit(1) .execute(); if (users && users.length) { return users[0]; } return undefined; }
/** * 举报沸点 */ async report(boilingPointID: number, reporter: number, reason: number) { this.boilingPointReportRepository.insert({ boilingPointID, reporter, reason, createdAt: new Date(), }); }
async createChapter(bookID: number, chapterName: string, userID: number) { const chapter = new HandBookChapter(); chapter.name = chapterName; chapter.bookID = bookID; chapter.userID = userID; chapter.browseCount = chapter.commentCount = 0; chapter.rootCommentCount = 0; chapter.tryRead = false; chapter.createdAt = new Date(); chapter.updatedAt = chapter.createdAt; return await this.handBookChapterRepository.save(chapter); }
async isUserLiked(articleID: number, userID: number): Promise<boolean> { const sql = `SELECT article_id, user_id FROM like_articles WHERE article_id = ${articleID} AND user_id = ${userID}`; let result = await this.articleRepository.manager.query(sql); result = result || []; if (result.length) { return true; } return false; }
async findUsers(where, select): Promise<User[]> { const users = await this.userRepository.find({ select, where, }); return users; }
async unpublish(id: number) { return await this.bookRepository.update({ id, }, { status: BookStatus.BookUnpublish, }); }
async isChapterExist(id: number): Promise<boolean> { const chapter = await this.chapterRepository.findOne({ select: ['id'], where: { id, }, }); return chapter !== null; }
async detail(id: number) { return await this.handBookRepository.findOne({ select: ['id', 'name', 'introduce', 'summary', 'authorIntro', 'price', 'completionAt', 'isAllDone', 'coverURL', 'isAgree'], where: { id, }, }); }
async isUserNameExist(username: string) { const user: User | undefined = await this.userRepository.findOne({ select: ['id'], where: { username, }, }); return !!user; }
async findUser(where, select) { const user = await this.userRepository.findOne({ select, where, }); return user; }