Edits history of script submission #15414 for ' Create time-off request (deel)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    /**
     * Create time-off request
     * Create time-off request
     **Token scopes**: `time-off:write`
     */
    export async function main(auth: RT.Deel, body: Body) {
    	const url = new URL(`https://api.letsdeel.com/rest/v2/time_offs`)
    
    	const formData = new FormData()
    	for (const [k, v] of Object.entries(body)) {
    		if (v !== undefined && v !== '') {
    			formData.append(k, String(v))
    		}
    	}
    	const response = await fetch(url, {
    		method: 'POST',
    		headers: {
    			'Content-Type': 'application/json',
    			Authorization: 'Bearer ' + auth.apiKey
    		},
    		body: JSON.stringify(body)
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    
    /* eslint-disable */
    /**
     * This file was automatically generated by json-schema-to-typescript.
     * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
     * and run json-schema-to-typescript to regenerate this file.
     */
    
    /**
     * The time off request data
     */
    export interface Body {
    	/**
    	 * The time off request data
    	 */
    	data?: {
    		/**
    		 * The dates breakdown for the time off request.
    		 */
    		dates?: {
    			date: string | string
    			/**
    			 * The amount taken in hours during this specific date. It can not exceed the maximum allowed hours for the date.
    			 */
    			hours?: number
    			/**
    			 * The amount of time off requested for the date. It must be in the same time unit as in the total amount for the time off request.
    			 */
    			amount?: number
    			/**
    			 * The type of day for the time off request. All dates must follow the same type.
    			 */
    			day_type?: 'HALF_DAY' | 'FULL_DAY' | 'PERCENTAGE' | 'HOURLY'
    			[k: string]: unknown
    		}[]
    		/**
    		 * Reason for taking time off. This is complementary information for the time-off description. Useful to provide sub categories for the same policy.
    		 */
    		reason?: string
    		/**
    		 * Status for the time off request. When set to REQUESTED the time off should be reviewed later through the Approve/Reject time off api.
    		 */
    		status?: 'REQUESTED' | 'APPROVED'
    		/**
    		 * Whether the time off is paid or unpaid. By default it follows the policy configuration.
    		 */
    		is_paid?: boolean
    		end_date: string
    		/**
    		 * The time off policy id. Can be used in place of time_off_type_id
    		 */
    		policy_id?: string
    		start_date: string
    		/**
    		 * Description of the time off request. Some policies require that a description is provided.
    		 */
    		description?: string
    		/**
    		 * Contract id. This is the id of the contract associated with the time off request.
    		 */
    		contract_oid?: string
    		/**
    		 * Details of the event associated with the time off request. Required for event based policies such as parental leave.
    		 */
    		event_details?: {
    			/**
    			 * The birth date of the child. This is used for parental leave requests.
    			 */
    			birth_date: string
    			/**
    			 * The date of adoption. This is used for parental leave requests.
    			 */
    			adoption_date?: string
    			/**
    			 * Whether the birth was premature or not. This is used for parental leave requests.
    			 */
    			was_premature_birth: boolean
    			/**
    			 * Whether the birth was multiple or not. This is used for parental leave requests.
    			 */
    			had_multiple_children: boolean
    			[k: string]: unknown
    		}
    		/**
    		 * Deduction amount. Available for independent contractor's policies
    		 */
    		deduction_amount?: number
    		/**
    		 * The time off type id. Required when policy_id is not provided
    		 */
    		time_off_type_id?: string
    		/**
    		 * The time off event id. This is used to link the time off request to an event.
    		 */
    		time_off_event_id?: string
    		/**
    		 * This is the percentage of time off taken. This is used when the time off request is a percentage.
    		 */
    		time_off_percentage?: number
    		/**
    		 * The hris profile id of the recipient
    		 */
    		recipient_profile_id: string
    		/**
    		 * Description of the time off type. This is used when the policy is OTHER.
    		 */
    		other_type_description?: string
    		[k: string]: unknown
    	}
    	[k: string]: unknown
    }
    

    Submitted by hugo697 235 days ago