Skip to content

Commit

Permalink
Merge pull request #42 from B-ki/revert_id
Browse files Browse the repository at this point in the history
delete /all endpoint and revert /user/id
  • Loading branch information
B-ki authored Oct 26, 2023
2 parents d5b41c1 + 9dfa358 commit 4f261bc
Show file tree
Hide file tree
Showing 7 changed files with 5 additions and 35 deletions.
7 changes: 1 addition & 6 deletions api/src/modules/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ import { UserService } from './user.service';
export class UserController {
constructor(private userService: UserService) {}

@Get('/all')
async getAllUsers() {
return this.userService.getAll();
}

@Get('/id/:login')
@Get('/:login')
async getUserByLogin(@Param('login') login: string) {
return this.userService.getUnique(login);
}
Expand Down
4 changes: 0 additions & 4 deletions api/src/modules/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ import { FortyTwoProfile } from '../auth';
export class UserService {
constructor(private prisma: PrismaService) {}

async getAll(): Promise<User[]> {
return this.prisma.user.findMany();
}

async getUnique(login: string): Promise<User> {
const user = await this.prisma.user.findUnique({
where: {
Expand Down
4 changes: 2 additions & 2 deletions front/src/components/Auth/UseGetUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import ApiClient, { getUser } from '@/utils/apiAxios';
import UseSetUser from './UseSetUser';

const fetchUserData = async (login: string, token: string | null) => {
const response = await fetch(`/api/user/id/${login}`, {
const response = await fetch(`/api/user/${login}`, {
headers: { Authorization: `Bearer ${token}` },
});
if (!response.ok) {
Expand All @@ -19,7 +19,7 @@ const fetchUserData = async (login: string, token: string | null) => {

const UseGetUser = (props: { token: string; login: string }) => {
// This doesn't work because enabled parameter isn't correctly use with useApi()
//const query = useApi().get('my user', `/user/id/${props.login}`, { enabled: !!props.token }) as UseQueryResult<userDto>;
//const query = useApi().get('my user', `/user/${props.login}`, { enabled: !!props.token }) as UseQueryResult<userDto>;

const query = useQuery(['userData', props.login], () => fetchUserData(props.login, props.token), {
enabled: !!props.token,
Expand Down
2 changes: 1 addition & 1 deletion front/src/contexts/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }): Promi
const token = localStorage.getItem('token');
console.log('[AuthContext]', token);
if (token) {
const query = useApi().get('my user', `/user/id/${user?.login}`) as UseQueryResult<userDto>;
const query = useApi().get('my user', `/user/${user?.login}`) as UseQueryResult<userDto>;
setUser(dummyUserDto);
}
};
Expand Down
2 changes: 1 addition & 1 deletion front/src/utils/apiAxios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default class ApiClient implements IApiClient {
export async function getUser(login: string): Promise<userDto | void> {
try {
const userData = await ApiClient.getInstance()
.get<userDto>(`/user/id/${login}`)
.get<userDto>(`/user/${login}`)
.then((userData) => {
console.log('User data:', userData);
});
Expand Down
5 changes: 0 additions & 5 deletions package.json

This file was deleted.

16 changes: 0 additions & 16 deletions pnpm-lock.yaml

This file was deleted.

0 comments on commit 4f261bc

Please sign in to comment.