Files
request-portal/src/webparts/requestPortal/shared/createdBy.ts
T
Тимур Городецкий 8578653c16 feat: changed get time logic to approvers
2026-08-13 10:01:08 +05:00

29 lines
1.2 KiB
TypeScript

import { getSP } from './pnp/pnpjs';
/** Инициатор заявки — из системного поля «Автор» (Created By) элемента списка. */
export interface IInitiator {
name: string;
email: string;
}
/**
* Прочитать инициатора (создателя) элемента списка по его Id.
* Источник — системное поле Author (Created By), заполняется SharePoint
* автоматически при создании, работает для любой формы без доп. колонок.
* Возвращает undefined, если элемент/автор недоступен (не роняем шапку).
*/
export async function getCreatedBy(listTitle: string, itemId: number): Promise<IInitiator | undefined> {
try {
const item = (await getSP()
.web.lists.getByTitle(listTitle)
.items.getById(itemId)
.select('Author/Title', 'Author/EMail')
.expand('Author')()) as { Author?: { Title?: string; EMail?: string } };
const author = item.Author;
if (!author) return undefined;
return { name: author.Title || '', email: author.EMail || '' };
} catch {
return undefined;
}
}