mongoose#_AllowStringsForIds TypeScript Examples

The following examples show how to use mongoose#_AllowStringsForIds. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Mongo.ts    From ModMail with MIT License 6 votes vote down vote up
async getLog(id: string, type: 'ID' | 'USER' | 'CHANNEL' = 'CHANNEL', open = true): Promise<LogDocument | null> {
		const filter: _FilterQuery<_AllowStringsForIds<Pick<Pick<Document<unknown>, '_id'>, '_id'>>> = {};

		if (type === 'ID')
			filter._id = id;
		else if (type === 'USER')
			filter['recipient.id'] = id;
		else
			filter.channelID = id;

		filter.open = open;
		filter.botID = this.caller.bot.user.id;

		return await Log.findOne(filter)
			.then((data: LogDocument) => data as LogDocument)
			.catch(() => null);
	}