Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/Tiyyo/SkillCoop
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiyyo committed May 6, 2024
2 parents b66404e + e9d9b1f commit 1b1e2d3
Show file tree
Hide file tree
Showing 81 changed files with 1,199 additions and 596 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/github-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ jobs:
npm install -g pnpm
pnpm install
pnpm clean:type
# pnpm schema build
# pnpm date build
# pnpm type build
Expand Down
3 changes: 2 additions & 1 deletion apps/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"db:seed:prod": "node dist/prisma/infrastructure/prisma/seed.js",
"db:seed:dev": "ts-node -r tsconfig-paths/register ./src/infrastructure/prisma/seed.ts",
"db:reset": "prisma migrate reset",
"db:studio": "prisma studio"
"db:studio": "prisma studio",
"clean:type": "node ./apps/api/src/config/update-types.js"
},
"dependencies": {
"@aws-sdk/client-cloudfront": "^3.454.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ export class ResponseFriendRequestDTO {
status_name: string;
@IsNotEmpty()
@IsString()
username: string;
username?: string;
}
6 changes: 3 additions & 3 deletions apps/api/src/application/usecases/friend/friend.usecases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class FriendUsecases {
private readonly sendFriendRequestService: SendFriendRequestService,
private readonly pendingFriendRequestService: PendingFriendRequestService,
@Inject('EmitEventService') private eventEmitter: EmitEventInterface,
) {}
) { }

async sendRequst(adderId: string, friendId: string) {
await this.sendFriendRequestService.execute(adderId, friendId);
Expand Down Expand Up @@ -42,8 +42,8 @@ export class FriendUsecases {

if (data.status_name === 'confirmed') {
this.eventEmitter.friendRequestAccepted({
profileId: data.friend_id,
instigatorId: data.adder_id,
profileId: data.adder_id,
instigatorId: data.friend_id,
});
}
return { success: true, username: data.username, status: data.status_name };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ export class UserPreferencesUsecases {
private readonly languagePreferenceAdapter: LanguagePreferenceAdapter,
private readonly notificationPreferenceAdapter: NotificationPreferenceAdapter,
private readonly userPreferencesService: UserPreferencesService,
) {}
) { }

async updateTheme(userId: string, name: string) {
async updateTheme(userId: string, name: 'light' | 'dark') {
return await this.themePreferenceAdapter.updateOne(
{ user_id: userId },
{ name },
Expand Down
24 changes: 24 additions & 0 deletions apps/api/src/config/update-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*eslint-disable */
const fs = require('fs');
const path = require('path');

function readTypeFile() {
const filePath = path.resolve(
__dirname,
'../infrastructure/kysely/database.type.ts',
);
const file = fs.readFileSync(filePath, 'utf-8');
const lines = file.split('\n');
const generatedTypeLines = lines.map((line) => {
if (!line.includes('export type') && line.includes('Generated')) {
const insideChevrons = line.match(/<(.*)>/)[1];
const key = line.split(' Generated')[0];
const newLine = `${key} ${insideChevrons};`;
return newLine;
}
return line;
});
const newFiles = generatedTypeLines.join('\n');
fs.writeFileSync(filePath, newFiles);
}
readTypeFile();
2 changes: 1 addition & 1 deletion apps/api/src/domain/entities/event.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export type EventAggr = EventCoreEntity & {
score_team_2: number | null;
participants: EventParticipant[];
confirmed_participants: number;
user_status: string;
user_status?: string;
};

export type LastSharedEvent = {
Expand Down
3 changes: 1 addition & 2 deletions apps/api/src/domain/services/image/local-image.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ export class LocalImage {
originalname: string;
mimetype: string;
}> {
const minmeType = this.filename.split('.').pop();
console.log('minmeType', minmeType);
// const minmeType = this.filename.split('.').pop();
return { buffer: Buffer.from('s'), originalname: 's', mimetype: 's' };
// const filePath = path.join(dirname, pathToPublicFolder + this.filename);
// try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export type NotificationSubtype =

@Injectable()
export class NotificationBuilderMessageService {
constructor() {}
constructor() { }
build({
subtype,
username,
Expand Down Expand Up @@ -71,7 +71,6 @@ export class NotificationBuilderMessageService {
'Notifcation subtype not implemented',
'NotificationBuilderMessageService',
);
break;
}
}
private buildEventInfosHasBeenUpdatedMessage(eventDate: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { EventEmitter2 } from '@nestjs/event-emitter';

@Injectable()
export class NotificationDispatchService {
constructor(private readonly eventEmiter: EventEmitter2) {}
constructor(private readonly eventEmiter: EventEmitter2) { }
dispatch(notification: any) {
if (!notification || !notification.transports) {
console.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class InfosNotificationService {
constructor(
private readonly profileAdapter: ProfileAdapter,
private readonly eventQueriesAdapter: EventQueriesAdapter,
) {}
) { }
async get({
type,
eventId,
Expand Down Expand Up @@ -74,7 +74,7 @@ export class InfosNotificationService {
const profile = await this.profileAdapter.findOne({
profile_id: profileId,
});
return new InstigatorInfos(profile.avatar_url, profile.username).get;
return new InstigatorInfos(profile?.avatar_url, profile?.username).get;
}
async getEventInfos(eventId: number): Promise<{
avatar_url: string | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ import { NotificationPipelineService } from '../notification-pipeline.service';
export class FriendRequestNotificationService {
constructor(
private readonly notificationPipelineService: NotificationPipelineService,
) {}
) { }
notify(subscriberId: string, instigatorId: string) {
return this.notificationPipelineService.notify({
type: 'friend',
subtype: 'userHasBeenAddedToFriendlist',
subtype: 'userReceivedFriendRequest',
instigatorId,
profileId: subscriberId,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { NotificationPreferenceService } from './notification-preference.service
import { LanguagePreferenceService } from './language-preference.service';
import { ThemePreferenceService } from './theme-preference.service';
import { UserPreferencesAdapter } from 'src/infrastructure/kysely/adapters/user-preferences.adapter';
import { UserPreferences } from 'src/domain/entities/user-preferences.entity';
import { ApplicationException } from 'src/application/exceptions/application.exception';

@Injectable()
export class UserPreferencesService {
Expand All @@ -11,17 +13,26 @@ export class UserPreferencesService {
private readonly languagePreferenceService: LanguagePreferenceService,
private readonly themePreferenceService: ThemePreferenceService,
private readonly userPreferencesAdapter: UserPreferencesAdapter,
) {}
) { }
async get(id: string) {
let preferences: UserPreferences;
try {
return await this.userPreferencesAdapter.get(id);
preferences = await this.userPreferencesAdapter.get(id);
if (preferences) return preferences;
} catch (error) {
this.generate(id);
return await this.userPreferencesAdapter.get(id);
throw new ApplicationException(
'Error while getting user preferences',
'UserPreferencesService',
);
}
if (!preferences) {
await this.generate(id);
preferences = await this.userPreferencesAdapter.get(id);
return preferences;
}
}
async generate(userId: string) {
Promise.all([
Promise.allSettled([
this.notificationPreferenceService.generate(userId),
this.languagePreferenceService.generate(userId),
this.themePreferenceService.generate(userId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class LoginDemoUserController {
failedAttemps: loginTrack.failedAttempts,
});
}

if (
loginTrack.success &&
loginTrack.accessToken &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class LoginUserController {
constructor(
private readonly loginUsecases: LoginUserUsecases,
private readonly envVarible: NestEnvVariableAdapterService,
) {}
) { }
@Post('login')
@HttpCode(200)
async login(@Body() body: LoginUserDTO, @Res() res: Response) {
Expand All @@ -20,6 +20,7 @@ export class LoginUserController {
body.email,
body.password,
);

if (!loginTrack.success) {
return res.status(loginTrack.status).json({
error: loginTrack.error,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { FriendUsecases } from 'src/application/usecases/friend/friend.usecases'

@Controller('friends')
export class ResponseRequestFriendController {
constructor(private readonly friendUsecases: FriendUsecases) {}
@Patch('')
constructor(private readonly friendUsecases: FriendUsecases) { }
@Patch()
async response(@Body() body: ResponseFriendRequestDTO) {
return await this.friendUsecases.respondToRequest(body);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { Body, Controller, HttpCode, Post } from '@nestjs/common';
import { Body, Controller, HttpCode, Patch } from '@nestjs/common';
import { MarkNotificationDTO } from 'src/application/dto/mark-notification.dto';
import { NotificationUsecases } from 'src/application/usecases/notification/notification.usecases';

@Controller('notification')
export class MarkAsReadNotificationController {
constructor(private readonly notificationUsecases: NotificationUsecases) {}
constructor(private readonly notificationUsecases: NotificationUsecases) { }

@Post()
@Patch()
@HttpCode(200)
async markAsRead(@Body() body: MarkNotificationDTO) {
await this.notificationUsecases.markAsRead(body.notificationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,21 @@ export class GetMeController {
@Inject('TokenService') private tokenService: TokenServiceInterface,
private readonly envVariableService: NestEnvVariableAdapterService,
private readonly getMeUserUsecases: GetMeUserUsecases,
) {}
) { }

@Get('me')
async getMe(@Req() req: Request, @Res() res: Response) {
const authHeaders = req.headers.Authorization || req.headers.authorization;
let token: string;

if (
authHeaders &&
typeof authHeaders === 'string' &&
authHeaders.startsWith('Bearer')
) {
token = authHeaders.split(' ')[1];
}

if (!token) {
throw new AccessTokenException(
'No access token provided',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ import {
@Injectable()
export class EventParticipantAdapter
extends CoreAdapter<'profile_on_event'>
implements EventParticipantRepository
{
implements EventParticipantRepository {
constructor(@Inject('dbClient') protected dbClient: Kysely<DB>) {
super(dbClient);
this.tableName = 'profile_on_event';
Expand Down Expand Up @@ -85,6 +84,7 @@ export class EventParticipantAdapter
}
}
async upsert(data: Partial<EventParticipantEntity>) {
console.log('data', data);
const dataWithCreatedAt = addCreatedISOStringDate(data);
try {
const result = await this.client
Expand Down
Loading

0 comments on commit 1b1e2d3

Please sign in to comment.