lodash#negate TypeScript Examples

The following examples show how to use lodash#negate. 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: update-one-user.ts    From js-client with MIT License 6 votes vote down vote up
makeUpdateOneUser = (context: APIContext) => {
	const updateOneUserLockedState = makeUpdateOneUserLockedState(context);
	const updateOneUserInformation = makeUpdateOneUserInformation(context);
	const updateOneUserRole = makeUpdateOneUserRole(context);
	const updateOneUserPassword = makeUpdateOneUserPassword(context);
	const getOneUser = makeGetOneUser(context);
	const updateOneUserSearchGroup = makeUpdateOneUserSearchGroup(context);

	return async (data: UpdatableUser): Promise<User> => {
		try {
			const promises: Array<Promise<void>> = [];

			// Update .locked
			if (isBoolean(data.locked)) promises.push(updateOneUserLockedState(data.id, data.locked));

			// Update .role
			if (isValidUserRole(data.role)) promises.push(updateOneUserRole(data.id, data.role));

			// Update .username .name or .email
			if ([data.username, data.name, data.email].some(negate(isUndefined)))
				promises.push(updateOneUserInformation(data));

			// Update password
			if (isString(data.password)) promises.push(updateOneUserPassword(data.id, data.password, data.currentPassword));

			// Search group ID
			if (isNumericID(data.searchGroupID) || isNull(data.searchGroupID))
				promises.push(updateOneUserSearchGroup(data.id, data.searchGroupID));

			await Promise.all(promises);
			return await getOneUser(data.id);
		} catch (err) {
			if (err instanceof Error) throw err;
			throw Error('Unknown error');
		}
	};
}