Skip to content
Snippets Groups Projects
Commit 6308af85 authored by Matt Kirby's avatar Matt Kirby
Browse files

Added request datastore

parent a989166a
No related branches found
No related tags found
1 merge request!15Add Friend service
import RequestSchema from '../Database/Schemas/RequestSchema';
import { FriendRequest } from '../Types/Request';
import { DataStore } from './DataStore';
/**
* Contains actions pertaining to storing and accessing Requests
*/
class RequestDataStore extends DataStore<any>{
public newRequest = async (sourceUserId: string, targetUserId: string): Promise<FriendRequest> => {
return await this.Model.create({
SourceUser: sourceUserId,
TargetUser: targetUserId
});
};
/**
* Store action for getting requests for a user
* @param itemCount
* @returns
*/
public getRequests = async (userId: string): Promise<FriendRequest[]> => {
return await this.Model.find({TargetUser: userId}).sort({$natural: -1})
}
/**
* Find and delete a request if it exists.
* @param requestId
* @returns
*/
public handleRequestById = async (requestId: string): Promise<FriendRequest> => {
const result = await this.Model.findByIdAndDelete(requestId)
if (result === null){
throw new Error ("Invalid request id!")
}
return result;
}
/**
* Get a request by its id
* @param requestId
* @returns
*/
public GetRequestById = async (requestId: string): Promise<FriendRequest> => {
const result = await this.Model.findById(requestId)
if(result === null){
throw new Error ("Invalid request id!")
}
return result;
}
}
export default new RequestDataStore('Request', RequestSchema)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment