|
@@ -1,97 +0,0 @@
|
|
|
-/**
|
|
|
|
|
- * Example usage of the CosmoeClient
|
|
|
|
|
- * Demonstrates how to use all the API endpoints
|
|
|
|
|
- */
|
|
|
|
|
-
|
|
|
|
|
-import { CosmoeClient } from './client/cosmoe';
|
|
|
|
|
-
|
|
|
|
|
-async function example() {
|
|
|
|
|
- const client = new CosmoeClient();
|
|
|
|
|
-
|
|
|
|
|
- try {
|
|
|
|
|
- // 1. Get authentication token
|
|
|
|
|
- console.log('Getting authentication token...');
|
|
|
|
|
- const tokenResult = await client.getToken('your_username', 'your_password');
|
|
|
|
|
- if (tokenResult.code === 200) {
|
|
|
|
|
- console.log('Successfully authenticated:', tokenResult.data);
|
|
|
|
|
- } else {
|
|
|
|
|
- console.error('Authentication failed:', tokenResult.msg);
|
|
|
|
|
- return;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 2. Get events list
|
|
|
|
|
- console.log('\nGetting events list...');
|
|
|
|
|
- const eventsResult = await client.getEvents();
|
|
|
|
|
- if (eventsResult.code === 200) {
|
|
|
|
|
- console.log('Available events:', eventsResult.data);
|
|
|
|
|
-
|
|
|
|
|
- // Get details of the first event if any exist
|
|
|
|
|
- if (eventsResult.data.length > 0) {
|
|
|
|
|
- const firstEvent = eventsResult.data[0];
|
|
|
|
|
- console.log(`\nGetting details for event: ${firstEvent.name} on ${firstEvent.event_date}`);
|
|
|
|
|
-
|
|
|
|
|
- const eventDetailResult = await client.getEventDetail(Number(firstEvent.id));
|
|
|
|
|
- if (eventDetailResult.code === 200) {
|
|
|
|
|
- console.log('Event details:', eventDetailResult.data);
|
|
|
|
|
-
|
|
|
|
|
- // 3. Book an event (example with first available time slot)
|
|
|
|
|
- const firstTimeSlot = eventDetailResult.data.slots[0];
|
|
|
|
|
- if (firstTimeSlot && firstTimeSlot.remaining > 0) {
|
|
|
|
|
- console.log(`\nBooking event ${firstEvent.id} at ${firstTimeSlot.range}...`);
|
|
|
|
|
-
|
|
|
|
|
- const bookingResult = await client.bookEvent({
|
|
|
|
|
- event_id: Number(firstEvent.id),
|
|
|
|
|
- time_slot: firstTimeSlot.range,
|
|
|
|
|
- user_note: 'Booking via CosmoeBot'
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- if (bookingResult.code === 200) {
|
|
|
|
|
- console.log('Booking successful:', bookingResult.msg);
|
|
|
|
|
- } else {
|
|
|
|
|
- console.error('Booking failed:', bookingResult.msg);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- console.error('Failed to get event details:', eventDetailResult.msg);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- console.error('Failed to get events:', eventsResult.msg);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 4. Get user profile and statistics
|
|
|
|
|
- console.log('\nGetting user profile...');
|
|
|
|
|
- const profileResult = await client.getProfile();
|
|
|
|
|
- if (profileResult.code === 200) {
|
|
|
|
|
- console.log('User profile:', profileResult.data);
|
|
|
|
|
- } else {
|
|
|
|
|
- console.error('Failed to get profile:', profileResult.msg);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 5. Get user's booking history
|
|
|
|
|
- console.log('\nGetting booking history...');
|
|
|
|
|
- const bookingsResult = await client.getMyBookings();
|
|
|
|
|
- if (bookingsResult.code === 200) {
|
|
|
|
|
- console.log('Booking history:', bookingsResult.data);
|
|
|
|
|
- } else {
|
|
|
|
|
- console.error('Failed to get booking history:', bookingsResult.msg);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- // 6. Change password example (uncomment to use)
|
|
|
|
|
- /*
|
|
|
|
|
- console.log('\nChanging password...');
|
|
|
|
|
- const passwordChangeResult = await client.changePassword('current_password', 'new_password');
|
|
|
|
|
- if (passwordChangeResult.code === 200) {
|
|
|
|
|
- console.log('Password changed successfully:', passwordChangeResult.msg);
|
|
|
|
|
- } else {
|
|
|
|
|
- console.error('Password change failed:', passwordChangeResult.msg);
|
|
|
|
|
- }
|
|
|
|
|
- */
|
|
|
|
|
-
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- console.error('Error occurred:', error);
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// Run the example
|
|
|
|
|
-example().catch(console.error);
|
|
|