WIP(ApPersonService.ts): analyzeAttachments

- Field型を事前に定義しておくように

- `attachments`が`IObject`だった場合、返り値が`{ fields: [] }`になるようだが構わないのか?
- `toArray()`を通すべきでは?
This commit is contained in:
okayurisotto 2023-07-02 19:15:45 +09:00
parent d276dabf26
commit 785a5f6f68

View file

@ -48,6 +48,8 @@ import type { IActor, IObject } from '../type.js';
const nameLength = 128; const nameLength = 128;
const summaryLength = 2048; const summaryLength = 2048;
type Field = Record<'name' | 'value', string>;
@Injectable() @Injectable()
export class ApPersonService implements OnModuleInit { export class ApPersonService implements OnModuleInit {
private utilityService: UtilityService; private utilityService: UtilityService;
@ -576,11 +578,10 @@ export class ApPersonService implements OnModuleInit {
} }
@bindThis @bindThis
public analyzeAttachments(attachments: IObject | IObject[] | undefined) { // TODO: `attachments`が`IObject`だった場合、返り値が`{ fields: [] }`になるようだが構わないのか?
const fields: { public analyzeAttachments(attachments: IObject | IObject[] | undefined): { fields: Field[] } {
name: string, const fields: Field[] = [];
value: string
}[] = [];
if (Array.isArray(attachments)) { if (Array.isArray(attachments)) {
for (const attachment of attachments.filter(isPropertyValue)) { for (const attachment of attachments.filter(isPropertyValue)) {
fields.push({ fields.push({