mirror of
https://github.com/myfatemi04/wheelshare-old-backend.git
synced 2025-04-21 12:10:17 -04:00
rename post to pool
This commit is contained in:
parent
b09bb33b95
commit
dfc06182a4
14
src/api.ts
14
src/api.ts
|
@ -1,5 +1,5 @@
|
|||
import { Router } from 'express';
|
||||
import { getGroupByID, getPostByID, getUserByID } from './data';
|
||||
import { getGroupByID, getPoolByID, getUserByID } from './data';
|
||||
|
||||
export const router = Router();
|
||||
|
||||
|
@ -18,16 +18,16 @@ router.get('/user', (req, res) => {
|
|||
}
|
||||
});
|
||||
|
||||
router.get('/post', (req, res) => {
|
||||
if (typeof req.query.postID != 'string') {
|
||||
router.get('/pool', (req, res) => {
|
||||
if (typeof req.query.poolID != 'string') {
|
||||
return;
|
||||
}
|
||||
|
||||
let postID = req.query.postID;
|
||||
let post = getPostByID(postID);
|
||||
let poolID = req.query.poolID;
|
||||
let pool = getPoolByID(poolID);
|
||||
|
||||
if (post) {
|
||||
res.json({ status: 'success', data: post });
|
||||
if (pool) {
|
||||
res.json({ status: 'success', data: pool });
|
||||
} else {
|
||||
res.json({ status: 'error', error: 'not_found' });
|
||||
}
|
||||
|
|
10
src/data.ts
10
src/data.ts
|
@ -15,9 +15,9 @@ export const users: Record<string, Carpool.User> = {
|
|||
export const groups: Record<string, Carpool.Group> = {};
|
||||
|
||||
/**
|
||||
* Records posts by id
|
||||
* Records pools by id
|
||||
*/
|
||||
export const posts: Record<string, Carpool.Post> = {};
|
||||
export const pools: Record<string, Carpool.Pool> = {};
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -42,7 +42,7 @@ export function getGroupsWithUser(userID: string) {
|
|||
*/
|
||||
export function getPostsByUser(userID: string) {
|
||||
let postIDs = [];
|
||||
for (let post of Object.values(posts)) {
|
||||
for (let post of Object.values(pools)) {
|
||||
if (post.author_id == userID) {
|
||||
postIDs.push(post.id);
|
||||
}
|
||||
|
@ -55,8 +55,8 @@ export function getUserByID(userID: string): Carpool.User | undefined {
|
|||
return users[userID];
|
||||
}
|
||||
|
||||
export function getPostByID(postID: string): Carpool.Post | undefined {
|
||||
return posts[postID];
|
||||
export function getPoolByID(poolID: string): Carpool.Pool | undefined {
|
||||
return pools[poolID];
|
||||
}
|
||||
|
||||
export function getGroupByID(groupID: string): Carpool.Group | undefined {
|
||||
|
|
|
@ -18,7 +18,7 @@ namespace Carpool {
|
|||
|
||||
export type Status = 'pending' | 'cancelled' | 'completed' | 'interrupted';
|
||||
|
||||
export interface Post {
|
||||
export interface Pool {
|
||||
id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
|
|
Loading…
Reference in New Issue
Block a user