feat: newsletter subscribe (#968)
* feat: subscribe newsletter Signed-off-by: Innei <tukon479@gmail.com> * feat(subscribe): send email Signed-off-by: Innei <tukon479@gmail.com> * fix(template): email template override Signed-off-by: Innei <tukon479@gmail.com> * fix: newsletter template props Signed-off-by: Innei <tukon479@gmail.com> * fix: get master inside Signed-off-by: Innei <tukon479@gmail.com> * feat: add sort Signed-off-by: Innei <tukon479@gmail.com> * feat(api-client): add subscribe controller Signed-off-by: Innei <tukon479@gmail.com> --------- Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
47
packages/api-client/controllers/subscribe.ts
Normal file
47
packages/api-client/controllers/subscribe.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { IRequestAdapter } from '~/interfaces/adapter'
|
||||
import { IController } from '~/interfaces/controller'
|
||||
import { IRequestHandler } from '~/interfaces/request'
|
||||
import { SubscribeType } from '~/models/subscribe'
|
||||
import { autoBind } from '~/utils/auto-bind'
|
||||
|
||||
import { HTTPClient } from '../core'
|
||||
|
||||
declare module '../core/client' {
|
||||
interface HTTPClient<
|
||||
T extends IRequestAdapter = IRequestAdapter,
|
||||
ResponseWrapper = unknown,
|
||||
> {
|
||||
subscribe: SubscribeController<ResponseWrapper>
|
||||
}
|
||||
}
|
||||
|
||||
export class SubscribeController<ResponseWrapper> implements IController {
|
||||
base = 'subscribe'
|
||||
name = 'subscribe'
|
||||
|
||||
constructor(protected client: HTTPClient) {
|
||||
autoBind(this)
|
||||
}
|
||||
|
||||
public get proxy(): IRequestHandler<ResponseWrapper> {
|
||||
return this.client.proxy(this.base)
|
||||
}
|
||||
|
||||
subscribe(email: string, types: SubscribeType[]) {
|
||||
return this.proxy.post<never>({
|
||||
params: {
|
||||
email,
|
||||
types,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
unsubscribe(email: string, cancelToken: string) {
|
||||
return this.proxy.unsubscribe.get<string>({
|
||||
params: {
|
||||
email,
|
||||
cancelToken,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user