Skip to content

Commit

Permalink
changes: minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
josefrnandezz committed Sep 28, 2022
1 parent 6c3b3d7 commit 43f556b
Show file tree
Hide file tree
Showing 22 changed files with 118 additions and 86 deletions.
9 changes: 9 additions & 0 deletions apps/api/src/assets/templates/artist-follow-artist.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<p>Hola,</p>

<p>{{ name }} ha comenzado a seguirte: {{ name }}</p>
<p>
Puedes visitar su perfil en el siguiente enlace:
<a href="{{ url }}">>
Perfil de {{name}}
</a>
</p>
6 changes: 0 additions & 6 deletions apps/api/src/assets/templates/cancelado.hbs

This file was deleted.

7 changes: 0 additions & 7 deletions apps/api/src/assets/templates/confirmation.hbs

This file was deleted.

6 changes: 3 additions & 3 deletions apps/artists/components/layout/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BellOutlined, HomeOutlined } from '@ant-design/icons';
import { ApiOutlined, HomeOutlined } from '@ant-design/icons';
import { Col, Layout, Menu, Row, Space, Typography } from 'antd';
import { Session } from 'next-auth';
import Image from 'next/image';
Expand Down Expand Up @@ -51,8 +51,8 @@ export const Header = ({ session }: HeaderProps) => {
<Menu.Item key="home" icon={<HomeOutlined />}>
<Link href="/">Inicio</Link>
</Menu.Item>
<Menu.Item key="follows" icon={<BellOutlined />}>
<Link href="/follows">Subscripciones</Link>
<Menu.Item key="follows" icon={<ApiOutlined />}>
<Link href="/follows">Conexiones</Link>
</Menu.Item>
</Menu>
</Col>
Expand Down
16 changes: 8 additions & 8 deletions apps/artists/pages/follows/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { FollowType } from '@melomaniapp/contracts/follow';

import { useArtistFollows, useMyArtist } from '@melomaniapp/hooks';
import { useArtistFollows } from '@melomaniapp/hooks';

import { Avatar, Card, List, PageHeader, Spin, Tabs } from 'antd';
import { Avatar, Card, List, PageHeader, Spin } from 'antd';
import { useSession } from 'next-auth/client';
import Link from 'next/link';
import React from 'react';
Expand All @@ -21,7 +21,7 @@ const Follows: React.FC = () => {
style={{ margin: 'auto', borderRadius: '20px' }}
ghost={false}
onBack={() => window.history.back()}
title="Subscripciones"
title="Conexiones"
>
<List
itemLayout="vertical"
Expand All @@ -43,26 +43,26 @@ const Follows: React.FC = () => {
borderRadius: '20px',
}}
>
<Link href={`/artists/${item.followedToId}`}>
<Link href={`/artists/${item.followedTo._id}`}>
<List.Item>
<List.Item.Meta
avatar={
<Avatar
src={
<img
referrerPolicy="no-referrer"
src={item.artist?.imageUrl}
src={item.followedTo.imageUrl}
/>
}
size="large"
/>
}
title={
<Link href={`artists/${item.followedToId}`}>
{item.artist.name}
<Link href={`artists/${item.followedTo._id}`}>
{item.followedTo.name}
</Link>
}
description={item.artist.description}
description={item.followedTo.description}
/>
</List.Item>
</Link>
Expand Down
2 changes: 1 addition & 1 deletion apps/artists/pages/profile/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export const EditFanProfile: React.FC = () => {

<Form.Item
required={true}
name="genres"
name="genreIds"
label="Géneros musicales"
initialValue={artist?.genreIds.map((genre) => genre)}
trigger="onChangeHandler"
Expand Down
5 changes: 4 additions & 1 deletion apps/fans/components/ProfileHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,10 @@ export const ProfileHeader: React.FC<ProfileHeader> = ({
{!imageUrl ? (
<Avatar size={140} icon={<CustomerServiceOutlined />} />
) : (
<Avatar size={140} src={imageUrl} />
<Avatar
size={140}
src={<img referrerPolicy="no-referrer" src={imageUrl} />}
/>
)}
</div>
<Typography.Title>
Expand Down
7 changes: 6 additions & 1 deletion apps/fans/components/fans/FanProfileHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ export const FanProfileHeader: React.FC<FanProfileHeaderProps> = ({
{!session ? (
<Avatar size={140} icon={<UserOutlined />} />
) : (
<Avatar size={140} src={session.user?.image} />
<Avatar
size={140}
src={
<img referrerPolicy="no-referrer" src={session.user?.image} />
}
/>
)}
</div>
<Typography.Title>{name}</Typography.Title>
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: '3.2'

services:
eventstore.db:
image: eventstore/eventstore:20.10.2-buster-slim
image: ghcr.io/eventstore/eventstore@sha256:ab30bf2a2629e2c8710f8f7fdcb74df5466c6b3b2200c8e9ad8a797ed138012a
environment:
- EVENTSTORE_CLUSTER_SIZE=1
- EVENTSTORE_RUN_PROJECTIONS=All
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
interface ArtistProps {
_id: string;
name: string;
alias: string;
description: string;
Expand All @@ -7,9 +8,8 @@ interface ArtistProps {

interface Props {
_id: string;
followedById: string;
followedToId: string;
artist: ArtistProps;
followedBy: ArtistProps;
followedTo: ArtistProps;
}

export class FollowArtistArtistDTO {
Expand All @@ -19,9 +19,7 @@ export class FollowArtistArtistDTO {

public readonly _id: string;

public readonly followedById: string;

public readonly followedToId: string;
public readonly followedBy: ArtistProps;

public readonly artist: ArtistProps;
public readonly followedTo: ArtistProps;
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { EventDTO } from '@melomaniapp/contracts/event';
import { MailService } from '@melomaniapp/nestjs/mailer';
import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';

import { EventWasCancelled } from '../../../domain';
import { EventDocument, EVENTS_PROJECTION } from './events.schema';

Expand All @@ -13,14 +11,12 @@ export class EventWasCancelledProjection
{
constructor(
@InjectModel(EVENTS_PROJECTION)
private readonly events: Model<EventDocument>,
private readonly mailService: MailService
private readonly events: Model<EventDocument>
) {}

async handle(event: EventWasCancelled) {
const eventDto = await this.events
return await this.events
.findByIdAndDelete(event.aggregateId)
.lean<EventDTO>();
await this.mailService.sendEventWasCanceled(['[email protected]'], eventDto);
}
}
1 change: 1 addition & 0 deletions libs/nestjs/follow/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './infrastructure/follow.module';
export * from './infrastructure/read-model/follows/follow-user-event';
3 changes: 3 additions & 0 deletions libs/nestjs/follow/src/infrastructure/follow.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { EventStoreModule } from '@aulasoftwarelibre/nestjs-eventstore';
import { MailModule } from '@melomaniapp/nestjs/mailer';
import { UserModule } from '@melomaniapp/nestjs/user';
import { Module } from '@nestjs/common';
import { CqrsModule } from '@nestjs/cqrs';
import { MongooseModule } from '@nestjs/mongoose';
Expand All @@ -16,6 +18,7 @@ import { FollowService } from './services';
CqrsModule,
EventStoreModule.forFeature([Follow], eventTransformers),
MongooseModule.forFeature(followModels),
MailModule,
],
providers: [
...commandHandlers,
Expand Down
8 changes: 4 additions & 4 deletions libs/nestjs/follow/src/infrastructure/follow.providers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import {
} from '@melomaniapp/nestjs/establishment';

export const followProviders: Provider[] = [
{
provide: USER_FINDER,
useClass: UserFinder,
},
{
provide: FOLLOW_FINDER,
useClass: FollowFinder,
Expand All @@ -19,10 +23,6 @@ export const followProviders: Provider[] = [
provide: ARTIST_FINDER,
useClass: ArtistFinder,
},
{
provide: USER_FINDER,
useClass: UserFinder,
},
{
provide: GENRE_FINDER,
useClass: GenreFinder,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { FollowType } from '@melomaniapp/contracts/follow';
import { MailService } from '@melomaniapp/nestjs/mailer';
import { ArtistDocument, ARTISTS_PROJECTION } from '@melomaniapp/nestjs/artist';
import { EventsHandler, IEventHandler } from '@nestjs/cqrs';
import { InjectModel } from '@nestjs/mongoose';
import { Model } from 'mongoose';
import { ArtistWasFollowedByArtist } from '../../../domain';
import { ArtistWasFollowedByArtist, FollowedTo } from '../../../domain';
import {
FollowArtistArtistDocument,
FOLLOWS_ARTIST_ARTIST_PROJECTION,
} from './follow-artist-artist.schema';
import { UserDocument, USERS_PROJECTION } from '@melomaniapp/nestjs/user';

@EventsHandler(ArtistWasFollowedByArtist)
export class ArtistWasFollowedByArtistProjection
Expand All @@ -17,12 +18,27 @@ export class ArtistWasFollowedByArtistProjection
@InjectModel(FOLLOWS_ARTIST_ARTIST_PROJECTION)
private readonly follows: Model<FollowArtistArtistDocument>,
@InjectModel(ARTISTS_PROJECTION)
private readonly artists: Model<ArtistDocument>
private readonly artists: Model<ArtistDocument>,
@InjectModel(USERS_PROJECTION)
private readonly users: Model<UserDocument>,
private readonly mailService: MailService
) {}

async handle(event: ArtistWasFollowedByArtist) {
const artist = await this.artists
const followedTo = await this.artists
.findById(event.payload.followedToId)
.select({
_id: true,
name: true,
alias: true,
description: true,
imageUrl: true,
userId: true,
})
.lean();

const followedBy = await this.artists
.findById(event.payload.followedById)
.select({
_id: true,
name: true,
Expand All @@ -34,16 +50,29 @@ export class ArtistWasFollowedByArtistProjection

const follow = new this.follows({
_id: event.payload._id,
followedById: event.payload.followedById,
followedToId: event.payload.followedToId,
artist: {
name: artist.name,
alias: artist.alias,
description: artist.description,
imageUrl: artist.imageUrl,
followedTo: {
_id: followedTo._id,
name: followedTo.name,
alias: followedTo.alias,
description: followedTo.description,
imageUrl: followedTo.imageUrl,
},
followedBy: {
_id: followedBy._id,
name: followedBy.name,
alias: followedBy.alias,
description: followedBy.description,
imageUrl: followedBy.imageUrl,
},
});

await follow.save();

const userToNotify = await this.users.findById(followedTo.userId).lean();

await this.mailService.sendArtistFollowedArtist(userToNotify.email, {
id: followedBy._id,
name: followedBy.name,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ export type FollowArtistArtistDocument = FollowArtistArtistDTO & Document;
export const FollowArtistArtistSchema = new Schema(
{
_id: String,
followedById: String,
followedToId: String,
artist: {
followedBy: {
_id: String,
name: String,
alias: String,
description: String,
imageUrl: String,
},
followedTo: {
_id: String,
name: String,
alias: String,
description: String,
Expand Down
4 changes: 2 additions & 2 deletions libs/nestjs/mailer/src/lib/mailer.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import { MailerModule } from '@nestjs-modules/mailer';
import { HandlebarsAdapter } from '@nestjs-modules/mailer/dist/adapters/handlebars.adapter';
import { join } from 'path';

import { mailProvider, MailService } from './mailer.service';
import { MailService } from './mailer.service';

@Global()
@Module({
imports: [
MailerModule.forRoot({
transport: 'smtp://localhost:1025',
defaults: {
from: '"No Reply" <decano@gmail.com>',
from: '"No Reply" <info@melomaniapp.com>',
},
template: {
dir: join(__dirname, 'assets/templates'),
Expand Down
Loading

0 comments on commit 43f556b

Please sign in to comment.