Skip to content

Commit 52c2bb2

Browse files
authored
[SocialMedia][Lista] - Repository para lista as redes sociais disponiveis (#95)
* feat: add account repository * feat: add account repository for find user by id * test: test for mocking repository * test: implementation tests for account repository * feat: ensure create account users * test: ensure create account users * fix: imports order * fix: return function with await * fix: remove guide todos file * fix: remove @default at schema prisma * fix: import order user-repository * chore: update branch * fix: format of eol and import
1 parent a02d861 commit 52c2bb2

File tree

6 files changed

+62
-7
lines changed

6 files changed

+62
-7
lines changed

eslint.config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import js from '@eslint/js';
22
import eslintConfigPrettier from 'eslint-config-prettier';
33
import { defineFlatConfig } from 'eslint-define-config';
4-
import tsEslint from 'typescript-eslint';
54
import importPlugin from 'eslint-plugin-import';
65
import perfectionist from 'eslint-plugin-perfectionist';
76
import unicornPlugin from 'eslint-plugin-unicorn';
87
import vitestPlugin from 'eslint-plugin-vitest';
98
import globals from 'globals';
9+
import tsEslint from 'typescript-eslint';
1010

1111
import 'eslint-plugin-only-warn';
1212

@@ -56,7 +56,7 @@ export default defineFlatConfig([
5656
'import/no-named-as-default': 'warn',
5757
'import/no-named-as-default-member': 'warn',
5858
'import/no-unused-modules': 'warn',
59-
'import/order': 'warn',
59+
'import/order': 'off',
6060

6161
'perfectionist/sort-array-includes': 'warn',
6262
'perfectionist/sort-classes': 'warn',
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-- AlterTable
2+
ALTER TABLE "accounts" ALTER COLUMN "updated_at" SET DEFAULT CURRENT_TIMESTAMP;

src/features/user/controllers/user-controller.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import type { RequestHandler } from 'express';
22
import type { UserCreateModel } from '../models/user-create-model.js';
3-
import { userCreateSchema, userFindByIdSchema } from '../validators/index.js';
43
import type { UserFindByIdModel } from '../models/user-find-by-id-model.js';
4+
import { userCreateSchema, userFindByIdSchema } from '../validators/index.js';
55
import { userIdParamsSchema } from '../validators/user-id-schema.js';
6-
import type { Controller } from '@/shared/protocols/controller.js';
7-
import type { Service } from '@/shared/protocols/service.js';
6+
87
import type { Validator } from '@/shared/infra/validator/validator.js';
8+
import type { Controller } from '@/shared/protocols/controller.js';
99
import type { AsyncRequestHandler } from '@/shared/protocols/handlers.js';
1010
import { HttpStatusCode } from '@/shared/protocols/http-client.js';
11+
import type { Service } from '@/shared/protocols/service.js';
1112

1213
export class UserController implements Controller {
1314
create: AsyncRequestHandler = async (req, res, next) => {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { AccountRepository } from './account-repository.js';
2+
import { AccountMock } from '@/shared/test-helpers/mocks/account.mock.js';
3+
import { prisma } from 'mocks/prisma.js';
4+
5+
const makeSut = () => {
6+
const repository = new AccountRepository();
7+
8+
return { repository };
9+
};
10+
11+
describe('[Repositories] AccountRepository', () => {
12+
it('should call service for create account', async () => {
13+
const { repository } = makeSut();
14+
15+
const account = AccountMock.create();
16+
17+
await repository.create(account);
18+
19+
const { id, ...accountWithoutId } = account;
20+
21+
expect(prisma.account.create).toHaveBeenCalledWith({
22+
data: accountWithoutId,
23+
});
24+
});
25+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import type { Prisma } from '@prisma/client';
2+
import { database } from '@/shared/infra/database/database.js';
3+
4+
type CreateAccountParams = Prisma.Args<
5+
typeof database.account,
6+
'create'
7+
>['data'];
8+
export class AccountRepository {
9+
async create({ avatarUrl, socialMediaId, userId }: CreateAccountParams) {
10+
return await database.account.create({
11+
data: {
12+
avatarUrl,
13+
socialMediaId,
14+
userId,
15+
},
16+
});
17+
}
18+
19+
async findAccountsByUserId(id: string) {
20+
const socialMidias = await database.account.findMany({
21+
where: {
22+
userId: id,
23+
},
24+
});
25+
return socialMidias;
26+
}
27+
}

src/features/user/repositories/user-repository/user-repository.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { Prisma } from '@prisma/client';
2-
import { database } from '@/shared/infra/database/database.js';
31
import { prismaErrorHandler } from '@/shared/errors/prisma-error.js';
2+
import { database } from '@/shared/infra/database/database.js';
3+
import type { Prisma } from '@prisma/client';
44

55
type CreateUserParams = Prisma.Args<typeof database.user, 'create'>['data'];
66

0 commit comments

Comments
 (0)