61 lines
1.5 KiB
Plaintext
61 lines
1.5 KiB
Plaintext
// users.rhai - Functions for handling calendar users
|
|
|
|
import "utils" as utils;
|
|
import "../models/user_model" as user_model;
|
|
|
|
// Get all users
|
|
fn get_all_users() {
|
|
return user_model::get_sample_users();
|
|
}
|
|
|
|
// Get a specific user by ID
|
|
fn get_user(user_id) {
|
|
let users = get_all_users();
|
|
return utils::find_by_id(users, user_id);
|
|
}
|
|
|
|
// Get user by email
|
|
fn get_user_by_email(email) {
|
|
let users = get_all_users();
|
|
|
|
for user in users {
|
|
if user.email == email {
|
|
return user;
|
|
}
|
|
}
|
|
|
|
return #{}; // Return empty object if not found
|
|
}
|
|
|
|
// Get users by timezone
|
|
fn get_users_by_timezone(timezone) {
|
|
let users = get_all_users();
|
|
return utils::filter_by_property(users, "timezone", timezone);
|
|
}
|
|
|
|
// Create a new user
|
|
fn create_user(name, email, timezone, notification_time, default_calendar_id) {
|
|
// Generate a simple ID (in a real app, we would use a proper ID generation method)
|
|
let id = "user" + (get_all_users().len() + 1).to_string();
|
|
|
|
let preferences = user_model::create_user_preferences(
|
|
notification_time, default_calendar_id
|
|
);
|
|
|
|
return user_model::create_user(
|
|
id, name, email, timezone, preferences
|
|
);
|
|
}
|
|
|
|
// Format user details for display
|
|
fn format_user(user) {
|
|
if utils::is_empty(user) {
|
|
return "User not found";
|
|
}
|
|
|
|
return `${user.name} (${user.email})
|
|
Timezone: ${user.timezone}
|
|
Default Calendar: ${user.preferences.default_calendar_id}
|
|
Notification Time: ${user.preferences.notification_time} minutes before`;
|
|
}
|