typeorm#LessThan TypeScript Examples

The following examples show how to use typeorm#LessThan. 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: cve.ts    From crossfeed with Creative Commons Zero v1.0 Universal 6 votes vote down vote up
closeOpenVulnerabilities = async () => {
  const oneWeekAgo = new Date(
    new Date(Date.now()).setDate(new Date(Date.now()).getDate() - 7)
  );
  const openVulnerabilites = await Vulnerability.find({
    where: {
      state: 'open',
      lastSeen: LessThan(oneWeekAgo)
    }
  });
  for (const vulnerability of openVulnerabilites) {
    vulnerability.setState('remediated', true, null);
    await vulnerability.save();
  }
}
Example #2
Source File: paginate.ts    From nestjs-paginate with MIT License 6 votes vote down vote up
OperatorSymbolToFunction = new Map<FilterOperator, (...args: any[]) => FindOperator<string>>([
    [FilterOperator.EQ, Equal],
    [FilterOperator.GT, MoreThan],
    [FilterOperator.GTE, MoreThanOrEqual],
    [FilterOperator.IN, In],
    [FilterOperator.NULL, IsNull],
    [FilterOperator.LT, LessThan],
    [FilterOperator.LTE, LessThanOrEqual],
    [FilterOperator.BTW, Between],
    [FilterOperator.NOT, Not],
])
Example #3
Source File: content.service.ts    From radiopanel with GNU General Public License v3.0 6 votes vote down vote up
@Cron('* * * * *')
	public async sync(): Promise<void> {
		const contentToPublish = await this.contentRepository.find({
			where: {
				publishScheduledAt: LessThan(moment().endOf('minute').toDate()),
				published: false,
			},
		});

		contentToPublish.forEach((content) => {
			this.contentRepository.save({
				...content,
				published: true,
				publishedAt: new Date(),
				publishScheduledAt: null,
			});
		});

		const contentToUnPublish = await this.contentRepository.find({
			where: {
				unPublishScheduledAt: LessThan(moment().endOf('minute').toDate()),
				published: true,
			},
		});

		contentToUnPublish.forEach((content) => {
			this.contentRepository.save({
				...content,
				published: false,
				unPublishScheduledAt: null,
			});
		});
	}
Example #4
Source File: api-key.service.ts    From radiopanel with GNU General Public License v3.0 6 votes vote down vote up
@Cron('* * * * *')
	public async handleCron(): Promise<void> {
		this.apiKeyUsageRepository.delete({
			createdAt: LessThan(moment().subtract(1, 'hour').toDate()),
		})

		const tenant = await this.tenantService.findOne();

		if (!tenant) {
			return;
		}

		this.getKeyUsage(tenant)
	}
Example #5
Source File: index.ts    From fosscord-server with GNU Affero General Public License v3.0 5 votes vote down vote up
// https://discord.com/developers/docs/resources/channel#create-message
// get messages
router.get("/", async (req: Request, res: Response) => {
	const channel_id = req.params.channel_id;
	const channel = await Channel.findOneOrFail({ id: channel_id });
	if (!channel) throw new HTTPError("Channel not found", 404);

	isTextChannel(channel.type);
	const around = req.query.around ? `${req.query.around}` : undefined;
	const before = req.query.before ? `${req.query.before}` : undefined;
	const after = req.query.after ? `${req.query.after}` : undefined;
	const limit = Number(req.query.limit) || 50;
	if (limit < 1 || limit > 100) throw new HTTPError("limit must be between 1 and 100", 422);

	var halfLimit = Math.floor(limit / 2);

	const permissions = await getPermission(req.user_id, channel.guild_id, channel_id);
	permissions.hasThrow("VIEW_CHANNEL");
	if (!permissions.has("READ_MESSAGE_HISTORY")) return res.json([]);

	var query: FindManyOptions<Message> & { where: { id?: any; }; } = {
		order: { id: "DESC" },
		take: limit,
		where: { channel_id },
		relations: ["author", "webhook", "application", "mentions", "mention_roles", "mention_channels", "sticker_items", "attachments"]
	};
	

	if (after) {
		if (after > new Snowflake()) return res.status(422);
		query.where.id = MoreThan(after);
	}
	else if (before) { 
		if (before < req.params.channel_id) return res.status(422);
		query.where.id = LessThan(before);
	}
	else if (around) {
		query.where.id = [
			MoreThan((BigInt(around) - BigInt(halfLimit)).toString()),
			LessThan((BigInt(around) + BigInt(halfLimit)).toString())
		];
	}

	const messages = await Message.find(query);
	const endpoint = Config.get().cdn.endpointPublic;

	return res.json(
		messages.map((x: any) => {
			(x.reactions || []).forEach((x: any) => {
				// @ts-ignore
				if ((x.user_ids || []).includes(req.user_id)) x.me = true;
				// @ts-ignore
				delete x.user_ids;
			});
			// @ts-ignore
			if (!x.author) x.author = { id: "4", discriminator: "0000", username: "Fosscord Ghost", public_flags: "0", avatar: null };
			x.attachments?.forEach((y: any) => {
				// dynamically set attachment proxy_url in case the endpoint changed
				const uri = y.proxy_url.startsWith("http") ? y.proxy_url : `https://example.org${y.proxy_url}`;
				y.proxy_url = `${endpoint == null ? "" : endpoint}${new URL(uri).pathname}`;
			});
			
			/**
			Some clients ( discord.js ) only check if a property exists within the response,
			which causes erorrs when, say, the `application` property is `null`.
			**/
			
			for (var curr in x) {
				if (x[curr] === null)
					delete x[curr];
			}

			return x;
		})
	);
});
Example #6
Source File: prune.ts    From fosscord-server with GNU Affero General Public License v3.0 5 votes vote down vote up
inactiveMembers = async (guild_id: string, user_id: string, days: number, roles: string[] = []) => {
	var date = new Date();
	date.setDate(date.getDate() - days);
	//Snowflake should have `generateFromTime` method? Or similar?
	var minId = BigInt(date.valueOf() - Snowflake.EPOCH) << BigInt(22);

	/**
	idea: ability to customise the cutoff variable
	possible candidates: public read receipt, last presence, last VC leave
	**/
	var members = await Member.find({
		where: [
			{
				guild_id,
				last_message_id: LessThan(minId.toString())
			},
			{
				last_message_id: IsNull()
			}
		],
		relations: ["roles"]
	});
	console.log(members);
	if (!members.length) return [];

	//I'm sure I can do this in the above db query ( and it would probably be better to do so ), but oh well.
	if (roles.length && members.length) members = members.filter((user) => user.roles?.some((role) => roles.includes(role.id)));

	const me = await Member.findOneOrFail({ id: user_id, guild_id }, { relations: ["roles"] });
	const myHighestRole = Math.max(...(me.roles?.map((x) => x.position) || []));

	const guild = await Guild.findOneOrFail({ where: { id: guild_id } });

	members = members.filter(
		(member) =>
			member.id !== guild.owner_id && //can't kick owner
			member.roles?.some(
				(role) =>
					role.position < myHighestRole || //roles higher than me can't be kicked
					me.id === guild.owner_id //owner can kick anyone
			)
	);

	return members;
}