mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 21:40:39 +03:00
Update CollectionsService to remove CollectionPost usage
This commit is contained in:
parent
27f60b4ab5
commit
bd4fac451c
@ -1,47 +0,0 @@
|
||||
import {ValidationError} from '@tryghost/errors';
|
||||
import tpl from '@tryghost/tpl';
|
||||
import ObjectID from 'bson-objectid';
|
||||
|
||||
const messages = {
|
||||
invalidIDProvided: 'Invalid ID provided for CollectionPost'
|
||||
};
|
||||
|
||||
export class CollectionPost {
|
||||
id: string;
|
||||
postId: string;
|
||||
collectionId: string;
|
||||
sortOrder: number;
|
||||
deleted: boolean;
|
||||
|
||||
constructor(data: any) {
|
||||
this.id = data.id;
|
||||
this.postId = data.postId;
|
||||
this.collectionId = data.collectionId;
|
||||
this.sortOrder = data.sortOder;
|
||||
this.deleted = data.deleted;
|
||||
}
|
||||
|
||||
static async create(data: any): Promise<CollectionPost> {
|
||||
let id;
|
||||
|
||||
if (!data.id) {
|
||||
id = new ObjectID();
|
||||
} else if (typeof data.id === 'string') {
|
||||
id = ObjectID.createFromHexString(data.id);
|
||||
} else if (data.id instanceof ObjectID) {
|
||||
id = data.id;
|
||||
} else {
|
||||
throw new ValidationError({
|
||||
message: tpl(messages.invalidIDProvided)
|
||||
});
|
||||
}
|
||||
|
||||
return new CollectionPost({
|
||||
id: id.toHexString(),
|
||||
postId: data.post_id,
|
||||
collectionId: data.collection_id,
|
||||
sortOrder: data.sort_order, // NOTE: make sort_order required during creation
|
||||
deleted: false
|
||||
});
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
import {InMemoryRepository} from '@tryghost/in-memory-repository';
|
||||
import {CollectionPost} from './CollectionPost';
|
||||
|
||||
export class CollectionsPostsRepositoryInMemory extends InMemoryRepository<string, CollectionPost> {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
protected toPrimitive(entity: CollectionPost): object {
|
||||
return {
|
||||
id: entity.id,
|
||||
post_id: entity.postId,
|
||||
collection_id: entity.collectionId,
|
||||
sort_order: entity.sortOrder
|
||||
};
|
||||
}
|
||||
}
|
@ -1,20 +1,7 @@
|
||||
import {InMemoryRepository} from '@tryghost/in-memory-repository';
|
||||
import {Collection} from './Collection';
|
||||
import {CollectionPost} from './CollectionPost';
|
||||
|
||||
export class CollectionsRepositoryInMemory extends InMemoryRepository<string, Collection> {
|
||||
collectionsPostsRepository: any;
|
||||
|
||||
constructor(deps: any) {
|
||||
super();
|
||||
|
||||
this.collectionsPostsRepository = deps.collectionsPostsRepository;
|
||||
}
|
||||
|
||||
async saveCollectionPost(collectionPost: CollectionPost) {
|
||||
await this.collectionsPostsRepository.save(collectionPost);
|
||||
}
|
||||
|
||||
protected toPrimitive(entity: Collection): object {
|
||||
return {
|
||||
title: entity.title,
|
||||
|
Loading…
Reference in New Issue
Block a user