Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add packed item and change to item geolocation #448

Merged
merged 5 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export * from './enums/descriptionPlacement.js';
* Item
*/
export { type DiscriminatedItem, getMimetype } from './item/item.js';
export { type PackedItem } from './item/packedItem.js';
export * from './item/itemType.js';
export * from './item/itemUtils.js';
/**
Expand Down
16 changes: 16 additions & 0 deletions src/item/appItem/appItem.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
PartialItemFactory,
} from '../factory.js';
import { ItemType } from '../itemType.js';
import { PackedInformation } from '../packedItem.js';
import { AppItemType } from './appItem.js';
import { PermissionLevel } from '@/enums/permissionLevel/permissionLevel.js';
import { faker } from '@faker-js/faker';

export const AppItemFactory = (
Expand All @@ -22,3 +24,17 @@ export const AppItemFactory = (
},
};
};

export const PackedAppItemFactory = (
item: ItemFactoryInputType<AppItemType> = {},
packedInfo: Partial<PackedInformation>,
): ItemFactoryOutputType<AppItemType> => {
const newItem = AppItemFactory(item);
return {
...newItem,

// default packed info
permission: PermissionLevel.Admin,
...packedInfo,
};
};
16 changes: 16 additions & 0 deletions src/item/documentItem/documentItem.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
PartialItemFactory,
} from '../factory.js';
import { ItemType } from '../itemType.js';
import { PackedInformation } from '../packedItem.js';
import { DocumentItemType } from './documentItem.js';
import { PermissionLevel } from '@/enums/permissionLevel/permissionLevel.js';
import { faker } from '@faker-js/faker';

export const DocumentItemFactory = (
Expand All @@ -23,3 +25,17 @@ export const DocumentItemFactory = (
},
};
};

export const PackedDocumentItemFactory = (
item: ItemFactoryInputType<DocumentItemType> = {},
packedInfo: Partial<PackedInformation>,
): ItemFactoryOutputType<DocumentItemType> => {
const newItem = DocumentItemFactory(item);
return {
...newItem,

// default packed info
permission: PermissionLevel.Admin,
...packedInfo,
};
};
16 changes: 16 additions & 0 deletions src/item/etherpadItem/etherpadItem.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
PartialItemFactory,
} from '../factory.js';
import { ItemType } from '../itemType.js';
import { PackedInformation } from '../packedItem.js';
import { EtherpadItemType } from './etherpadItem.js';
import { PermissionLevel } from '@/enums/permissionLevel/permissionLevel.js';
import { faker } from '@faker-js/faker';

export const EtherpadItemFactory = (
Expand All @@ -24,3 +26,17 @@ export const EtherpadItemFactory = (
},
};
};

export const PackedEtherpadItemFactory = (
item: ItemFactoryInputType<EtherpadItemType> = {},
packedInfo: Partial<PackedInformation>,
): ItemFactoryOutputType<EtherpadItemType> => {
const newItem = EtherpadItemFactory(item);
return {
...newItem,

// default packed info
permission: PermissionLevel.Admin,
...packedInfo,
};
};
4 changes: 4 additions & 0 deletions src/item/factory.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { MemberFactory } from '../member/factory.js';
import { DiscriminatedItem } from './item.js';
import { buildPathFromIds } from './itemUtils.js';
import { PackedInformation } from './packedItem.js';
import { CCLicenseAdaptions } from '@/enums/ccLicenses.js';
import { faker } from '@faker-js/faker';

Expand All @@ -19,6 +20,9 @@ export type ItemFactoryOutputType<IT extends DiscriminatedItem> = Pick<
| 'updatedAt'
>;

export type PackedItemFactoryOutputType<IT extends DiscriminatedItem> =
ItemFactoryOutputType<IT> & PackedInformation;

export type ItemFactoryInputType<IT extends DiscriminatedItem> = Partial<IT> & {
parentItem?: Pick<IT, 'path'>;
};
Expand Down
30 changes: 30 additions & 0 deletions src/item/fileItem/fileItem.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
PartialItemFactory,
} from '../factory.js';
import { ItemType } from '../itemType.js';
import { PackedInformation } from '../packedItem.js';
import { LocalFileItemType, S3FileItemType } from './fileItem.js';
import { PermissionLevel } from '@/enums/permissionLevel/permissionLevel.js';
import { faker } from '@faker-js/faker';

export const LocalFileItemFactory = (
Expand All @@ -29,6 +31,20 @@ export const LocalFileItemFactory = (
};
};

export const PackedLocalFileItemFactory = (
item: ItemFactoryInputType<LocalFileItemType> = {},
packedInfo: Partial<PackedInformation>,
): ItemFactoryOutputType<LocalFileItemType> => {
const newItem = LocalFileItemFactory(item);
return {
...newItem,

// default packed info
permission: PermissionLevel.Admin,
...packedInfo,
};
};

export const S3FileItemFactory = (
item: ItemFactoryInputType<S3FileItemType> = {},
): ItemFactoryOutputType<S3FileItemType> => {
Expand All @@ -50,3 +66,17 @@ export const S3FileItemFactory = (
},
};
};

export const PackedS3FileItemFactory = (
item: ItemFactoryInputType<S3FileItemType> = {},
packedInfo: Partial<PackedInformation>,
): ItemFactoryOutputType<S3FileItemType> => {
const newItem = S3FileItemFactory(item);
return {
...newItem,

// default packed info
permission: PermissionLevel.Admin,
...packedInfo,
};
};
17 changes: 17 additions & 0 deletions src/item/folderItem/folderItem.factory.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import {
ItemFactoryInputType,
ItemFactoryOutputType,
PackedItemFactoryOutputType,
PartialItemFactory,
} from '../factory.js';
import { ItemType } from '../itemType.js';
import { PackedInformation } from '../packedItem.js';
import { FolderItemType } from './folderItem.js';
import { PermissionLevel } from '@/enums/permissionLevel/permissionLevel.js';

export const FolderItemFactory = (
item: ItemFactoryInputType<FolderItemType> = {},
Expand All @@ -20,3 +23,17 @@ export const FolderItemFactory = (
},
};
};

export const PackedFolderItemFactory = (
item: ItemFactoryInputType<FolderItemType> = {},
packedInfo: Partial<PackedInformation> = {},
): PackedItemFactoryOutputType<FolderItemType> => {
const newItem = FolderItemFactory(item);
return {
...newItem,

// default packed info
permission: PermissionLevel.Admin,
...packedInfo,
};
};
17 changes: 17 additions & 0 deletions src/item/h5pItem/h5pItem.factory.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import {
ItemFactoryInputType,
ItemFactoryOutputType,
PackedItemFactoryOutputType,
PartialItemFactory,
} from '../factory.js';
import { ItemType } from '../itemType.js';
import { PackedInformation } from '../packedItem.js';
import { H5PItemType } from './h5pItem.js';
import { PermissionLevel } from '@/enums/permissionLevel/permissionLevel.js';
import { faker } from '@faker-js/faker';

export const H5PItemFactory = (
Expand All @@ -25,3 +28,17 @@ export const H5PItemFactory = (
},
};
};

export const PackedH5PItemFactory = (
item: ItemFactoryInputType<H5PItemType> = {},
packedInfo: Partial<PackedInformation> = {},
): PackedItemFactoryOutputType<H5PItemType> => {
const newItem = H5PItemFactory(item);
return {
...newItem,

// default packed info
permission: PermissionLevel.Admin,
...packedInfo,
};
};
17 changes: 17 additions & 0 deletions src/item/linkItem/linkItem.factory.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import {
ItemFactoryInputType,
ItemFactoryOutputType,
PackedItemFactoryOutputType,
PartialItemFactory,
} from '../factory.js';
import { ItemType } from '../itemType.js';
import { PackedInformation } from '../packedItem.js';
import { LinkItemType } from './linkItem.js';
import { PermissionLevel } from '@/enums/permissionLevel/permissionLevel.js';
import { faker } from '@faker-js/faker';

export const LinkItemFactory = (
Expand Down Expand Up @@ -32,3 +35,17 @@ export const LinkItemFactory = (
},
};
};

export const PackedLinkItemFactory = (
item: ItemFactoryInputType<LinkItemType> = {},
packedInfo: Partial<PackedInformation> = {},
): PackedItemFactoryOutputType<LinkItemType> => {
const newItem = LinkItemFactory(item);
return {
...newItem,

// default packed info
permission: PermissionLevel.Admin,
...packedInfo,
};
};
14 changes: 14 additions & 0 deletions src/item/packedItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { ItemMembership } from '../itemMembership/itemMembership.js';
import { DiscriminatedItem } from './item.js';
import { ItemSettings } from './itemSettings.js';

export type PackedInformation = {
permission: ItemMembership['permission'] | null;
};

/**
* This type is used to define an item with more data such as:
* - permission
*/
export type PackedItem<S = ItemSettings> = DiscriminatedItem<S> &
PackedInformation;
17 changes: 17 additions & 0 deletions src/item/shortcutItem/shortcutItem.factory.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import {
ItemFactoryInputType,
ItemFactoryOutputType,
PackedItemFactoryOutputType,
PartialItemFactory,
} from '../factory.js';
import { ItemType } from '../itemType.js';
import { PackedInformation } from '../packedItem.js';
import { ShortcutItemType } from './shortcutItem.js';
import { PermissionLevel } from '@/enums/permissionLevel/permissionLevel.js';
import { faker } from '@faker-js/faker';

export const ShortcutItemFactory = (
Expand All @@ -23,3 +26,17 @@ export const ShortcutItemFactory = (
},
};
};

export const PackedShortcutItemFactory = (
item: ItemFactoryInputType<ShortcutItemType> = {},
packedInfo: Partial<PackedInformation> = {},
): PackedItemFactoryOutputType<ShortcutItemType> => {
const newItem = ShortcutItemFactory(item);
return {
...newItem,

// default packed info
permission: PermissionLevel.Admin,
...packedInfo,
};
};
4 changes: 2 additions & 2 deletions src/itemGeolocation/itemGeolocation.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { DiscriminatedItem } from '@/item/item.js';
import { PackedItem } from '@/item/packedItem.js';
import { UUID } from '@/types.js';

export type ItemGeolocation = {
id: UUID;
lat: number;
lng: number;
item: DiscriminatedItem;
item: PackedItem;
country: string | null;
addressLabel: string | null;
helperLabel: string | null;
Expand Down
18 changes: 18 additions & 0 deletions src/itemMembership/factory.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ItemMembership } from './itemMembership.js';
import { PermissionLevel } from '@/enums/permissionLevel/permissionLevel.js';
import { FolderItemFactory } from '@/item/folderItem/folderItem.factory.js';
import { MemberFactory } from '@/member/factory.js';
import { faker } from '@faker-js/faker';

export const ItemMembershipFactory = (
im: Partial<ItemMembership> & Pick<ItemMembership, 'item'> = {
item: FolderItemFactory(),
},
): ItemMembership => ({
id: faker.string.uuid(),
createdAt: faker.date.anytime().toISOString(),
updatedAt: faker.date.anytime().toISOString(),
member: MemberFactory(im.member),
permission: faker.helpers.enumValue(PermissionLevel),
...im,
});