-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5374 from gretchunkim/update-SPService-to-pull-cu…
…rrent-year-birthdays
- Loading branch information
Showing
11 changed files
with
86 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
v18.18.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 6 additions & 6 deletions
12
samples/react-birthdays/src/controls/happyBirthdayCard/IHappyBirthdayCardProps.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
export interface IHappyBirthdayCardProps { | ||
userName?:string | undefined; | ||
jobDescription?: string; | ||
userName: string; | ||
jobDescription: string; | ||
birthday: string; | ||
anniversary: boolean; | ||
userEmail:string; | ||
anniversary?: boolean; | ||
congratulationsMsg?: string; | ||
imageTemplate:string; | ||
} | ||
userEmail: string; | ||
imageTemplate: number; // Change this to a number to represent the index of the imageTemplate array | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions
14
samples/react-birthdays/src/controls/happybirthday/IUser.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
export interface IUser { | ||
key: string; | ||
userName:string; | ||
jobDescription?: string; | ||
birthday: string; | ||
userEmail: string; | ||
message: string; | ||
anniversary: boolean; | ||
key: string; // Unique key | ||
userName: string; // Name of the user | ||
message: string; // Birthday message | ||
anniversary: boolean; // Anniversary flag | ||
userEmail: string; // User's email address | ||
jobDescription: string; // Job title | ||
birthday: string; // ISO string of the birthday date | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
export interface IUser { | ||
key: string; | ||
userName:string; | ||
jobDescription?: string; | ||
birthday: string; | ||
userEmail: string; | ||
userName: string; | ||
message: string; | ||
anniversary: boolean; | ||
userEmail: string; | ||
jobDescription: string; | ||
birthday: string; // ISO string of the birthday | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,56 @@ | ||
import { WebPartContext } from "@microsoft/sp-webpart-base"; | ||
import { MSGraphClientV3 } from "@microsoft/sp-http"; | ||
import { MSGraphClientV3 } from "@microsoft/sp-http"; | ||
import * as moment from 'moment'; | ||
|
||
export class SPService { | ||
// private graphClient: MSGraphClientV3 = null; | ||
private graphClient: MSGraphClientV3; | ||
private birthdayListTitle: string = "Birthdays"; | ||
constructor(private _context: WebPartContext) { | ||
// private birthdayListTitle: string = "Birthdays"; | ||
|
||
} | ||
// Get Profiles | ||
public async getPBirthdays(upcommingDays: number): Promise<any[]> { | ||
let _results, _today: string, _month: number, _day: number; | ||
let _filter: string, _countdays: number, _f:number, _nextYearStart: string; | ||
let _FinalDate: string; | ||
constructor(private _context: WebPartContext) {} | ||
|
||
// Get Birthdays ignoring the year | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
public async getPBirthdays(upcomingDays: number): Promise<any[]> { | ||
try { | ||
_results = null; | ||
_today = '2000-' + moment().format('MM-DD'); | ||
_month = parseInt(moment().format('MM')); | ||
_day = parseInt(moment().format('DD')); | ||
_filter = "fields/Birthday ge '" + _today + "'"; | ||
// If we are in December we have to look if there are birthdays in January | ||
// we have to build a condition to select birthday in January based on number of upcommingDays | ||
// we can not use the year for test, the year is always 2000. | ||
console.log(_month); | ||
_countdays = _day + upcommingDays; | ||
_f = 0; | ||
if (_month === 12 && _countdays > 31) { | ||
_nextYearStart = '2000-01-01'; | ||
_FinalDate = '2000-01-'; | ||
_f = _countdays - 31; | ||
_FinalDate = _FinalDate + _f; | ||
_filter = "fields/Birthday ge '" + _today + "' or (fields/Birthday ge '" + _nextYearStart + "' and fields/Birthday le '" + _FinalDate + "')"; | ||
} | ||
else{ | ||
_FinalDate = '2000-'; | ||
if ((_countdays) > 31) { | ||
_f = _countdays - 31; | ||
_month = _month + 1; | ||
_FinalDate = _FinalDate +_month + '-' + _f; | ||
}else{ | ||
_FinalDate = _FinalDate +_month + '-' + _countdays; | ||
} | ||
_filter = "fields/Birthday ge '" + _today + "' and fields/Birthday le '" + _FinalDate + "'"; | ||
} | ||
const today = moment(); | ||
const todayMMDD = today.format('MM-DD'); // Get today's date as MM-DD | ||
const futureMMDD = today.add(upcomingDays, 'days').format('MM-DD'); // Calculate future date | ||
|
||
this.graphClient = await this._context.msGraphClientFactory.getClient('3'); | ||
_results = await this.graphClient.api(`sites/root/lists('${this.birthdayListTitle}')/items?orderby=Fields/Birthday`) | ||
|
||
// Fetch all birthdays without filtering | ||
const response = await this.graphClient | ||
.api(`sites/root/lists('Birthdays')/items?orderby=fields/Birthday`) | ||
.version('v1.0') | ||
.expand('fields') | ||
//.top(upcommingDays) | ||
.filter(_filter) | ||
.get(); | ||
|
||
return _results.value; | ||
// Filter results locally | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const filteredItems = response.value.filter((item: any) => { | ||
const birthday = item.fields.Birthday; | ||
if (!birthday) return false; // Skip if Birthday is missing | ||
|
||
const birthdayMMDD = moment(birthday).format('MM-DD'); // Extract MM-DD | ||
if (todayMMDD > futureMMDD) { | ||
// Handle year transition (December to January) | ||
return ( | ||
birthdayMMDD >= todayMMDD || // Later in the current year | ||
birthdayMMDD <= futureMMDD // Earlier in the next year | ||
); | ||
} else { | ||
// Normal case (same year) | ||
return birthdayMMDD >= todayMMDD && birthdayMMDD <= futureMMDD; | ||
} | ||
}); | ||
|
||
return filteredItems; | ||
} catch (error) { | ||
console.dir(error); | ||
console.error("Error fetching birthdays:", error); | ||
return Promise.reject(error); | ||
} | ||
} | ||
|
||
} | ||
|
||
export default SPService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters